1.

Solve : Only typing certain parts of a text file?

Answer» 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
i also would like to know this.
sorry I'm of no help.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
pauseQuote from: .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
Thank You welcom welcomWhat if you wanted only certain lines. Say lines 3, 5, 8, etc.?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
)


Discussion

No Comment Found