Read only first few lines from txt

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Hawk
Posts: 4
Joined: 24 Dec 2009 23:34
Location: India

Read only first few lines from txt

#1 Post by Hawk » 28 Dec 2009 15:34

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

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

#2 Post by !k » 28 Dec 2009 17:59

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
)
)

Hawk
Posts: 4
Joined: 24 Dec 2009 23:34
Location: India

Thanks!!!

#3 Post by Hawk » 29 Dec 2009 13:06

Works perfect as i want...

Thanks a lot... :D

Post Reply