Computing.Net > Forums > Programming > Get first line from a file

Get first line from a file

Reply to Message Icon

Original Message
Name: teognost
Date: January 8, 2007 at 05:55:29 Pacific
Subject: Get first line from a file
OS: WinXP SP2
CPU/Ram: 700 MHz/640 MB
Model/Manufacturer: Compaq
Comment:

I need to get from a file only the first line and to write it into other file-only using DOS commands.Till now I have managed to get the entire content of the file using a command like:
FOR /F "usebackq tokens=1,* delims=$" %%i in ("file1.txt") do (
echo %%i>>"file2.txt"
)
How can I take only the first line and not the whole content?
Thanks a lot for any info regarding this issue!


Report Offensive Message For Removal


Response Number 1
Name: IVO
Date: January 8, 2007 at 06:04:09 Pacific
Reply: (edit)

FOR /F "usebackq tokens=1,* delims=$" %%i in ("file1.txt") do (
echo %%i>>"file2.txt"
GoTo :OUT)
:OUT


Report Offensive Follow Up For Removal

Response Number 2
Name: teognost
Date: January 8, 2007 at 07:47:44 Pacific
Reply: (edit)

Many thanks,it is working perfectly!!


Report Offensive Follow Up For Removal

Response Number 3
Name: kazendar
Date: January 24, 2007 at 02:09:28 Pacific
Reply: (edit)

Please add && before GoTo (as && Goto)
or it will copy the whole file

Mr. Adel


Report Offensive Follow Up For Removal

Response Number 4
Name: titto
Date: January 25, 2007 at 08:20:29 Pacific
Reply: (edit)

Hi guys, basically I have the same problem but what I need is to get only the last line.
Could anyone tell me something?

Many thanks for any issue and advice


Report Offensive Follow Up For Removal

Response Number 5
Name: kazendar
Date: January 26, 2007 at 00:04:57 Pacific
Reply: (edit)

rem get last line
FOR /F "usebackq tokens=1,* delims=$" %%i in ("file1.txt") do echo %%i>"file2.txt"


Mr. Adel


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Get first line from a file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge