bat script to read lines from a txt file

May 2, 2011 at 17:59:20
Specs: Windows XP
Hi,

I'm just starting to do script.

I need help in creating a bat file to read first 5 lines from a text file and the output will be on another txt file.

Thanks in advance for the help


See More: bat script to read lines from a txt file

Report •


#1
May 3, 2011 at 00:29:01
In XP:

:: ==========================================
::
:: mae_27.bat Tue 03-05-2011 14:26:23.60
@echo off > newfile & setLocal enableDELAYedeXpansioN

set N=
for /f "tokens=* delims= " %%a in (myfile) do (
set /a N+=1
if !N! gtr 5 goto :eof
>> newfile echo.%%a
)


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
May 3, 2011 at 16:35:41
thanks very much.

you are a legend :)


Report •

#3
May 3, 2011 at 21:19:52
The above script is perfect but I need to add a command to be able to read txt files in a folder. I have like 60 txt files in a folder and needs to be able to read first 5 lines of each and every txt files in the folder.

reading the first 5 lines in each txt file has been resolved but reading thru all text files in a folder is another issue.


Report •

Related Solutions

#4
May 4, 2011 at 02:58:17
Do you want the 5 first lines from each in ONE file?


=====================================
Life is too important to be taken seriously.

M2


Report •

#5
May 4, 2011 at 04:18:28
yes. 5 first lines from each in ONE output file..


Report •

Ask Question