Page 1 of 1

Read only first few lines from txt

Posted: 28 Dec 2009 15:34
by Hawk
Hi There,

I need some help on reading a file content using a batch file.

For example, I would like to read the first 3 lines from a txt file and also remove those lines from the original file. So that i can use that file to read the next 3 lines next time by looping...

So my mission is to read the txt file 3 lines each time. Could someone help me on this?

Regards - Pradeep

Posted: 28 Dec 2009 17:59
by !k
it's blank:

Code: Select all

@echo off
setlocal enableextensions enabledelayedexpansion
set "i=1"
for /f "delims=" %%l in (file.txt) do (
if !i! LSS 4 (
echo line!i!: "%%l"
set /a i=!i!+1
)
if "!i!"=="4" (
set "i=1"
pause
)
)

Thanks!!!

Posted: 29 Dec 2009 13:06
by Hawk
Works perfect as i want...

Thanks a lot... :D