Computer Hope

Microsoft => Microsoft DOS => Topic started by: kamak on June 12, 2008, 05:14:48 AM

Title: Only typing certain parts of a text file
Post by: kamak on June 12, 2008, 05:14:48 AM
Hi all!

I was wondering if it's possible - and if so, how? - to print only a certain part of a text file with the type command.

e.g:

Text file:
Quote

llama
A llama is an animal, which is...

chocolate
A delicious food which...


coffee
A drink which helps keep....

How would i go about printing only say, the bit
Quote
chocolate
A delicious food which...
?


Thanks in advance,

Kamak
Title: Re: Only typing certain parts of a text file
Post by: Jacob on June 12, 2008, 10:25:45 AM
i also would like to know this.
sorry I'm of no help.
Title: Re: Only typing certain parts of a text file
Post by: .bat_man on June 12, 2008, 10:50:53 AM
u cant us the type command alone to generate such an output
put u can type out som lines of the file

@echo off
setlocal ENABLEDELAYEDEXPANSION
set /a cont=1
for /f "delims=" %%i in (file.txt) do (
if "!count!" EQU "3" echo %%i
set /a count=!count!+1
)
endlocal


this code will print the 3rd line
if u want it to print from the 3 to 5 row u have to do this


@echo off
setlocal ENABLEDELAYEDEXPANSION
set /a count=1
set /a count2=3
for /f "delims=" %%i in (New.txt) do (
if "!count2!" GTR "5" set /a count2=0
if "!count!" EQU "!count2!" (
echo %%i
set /a count2=!count2!+1
)
set /a count=!count!+1
)
endlocal
pause
Title: Re: Only typing certain parts of a text file
Post by: Jacob on June 12, 2008, 11:45:48 AM
u cant us the type command alone to generate such an output
put u can type out som lines of the file

@echo off
setlocal ENABLEDELAYEDEXPANSION
set /a cont=1
for /f "delims=" %%i in (file.txt) do (
if "!count!" EQU "3" echo %%i
set /a count=!count!+1
)
endlocal


this code will print the 3rd line
if u want it to print from the 3 to 5 row u have to do this


@echo off
setlocal ENABLEDELAYEDEXPANSION
set /a count=1
set /a count2=3
for /f "delims=" %%i in (New.txt) do (
if "!count2!" GTR "5" set /a count2=0
if "!count!" EQU "!count2!" (
echo %%i
set /a count2=!count2!+1
)
set /a count=!count!+1
)
endlocal
pause
Thank You :)
Title: Re: Only typing certain parts of a text file
Post by: .bat_man on June 12, 2008, 02:15:08 PM
welcom welcom
Title: Re: Only typing certain parts of a text file
Post by: Rook on August 11, 2008, 12:07:25 PM
What if you wanted only certain lines.  Say lines 3, 5, 8, etc.?
Title: Re: Only typing certain parts of a text file
Post by: Rook on August 11, 2008, 01:33:05 PM
Think I got it.  At least it is doing what I want.  Anyone have a cleaner way to do this, post for all to enjoy.

if exist File2 del file2
setlocal ENABLEDELAYEDEXPANSION
set count=0
for /f %%v in (File1) do (
   set /a count=!count!+1
   echo !count!
        if !count!==3 echo %%v > File2
        if !count!==5 echo %%v >> File2
        if !count!==10 echo %%v >> File2
        if !count!==70 echo %%v >> File2
        if !count!==71 echo %%v >> File2
        if !count!==72 echo %%v >> File2
   )