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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Get first line from a file

Reply to Message Icon

Name: teognost
Date: January 8, 2007 at 05:55:29 Pacific
OS: WinXP SP2
CPU/Ram: 700 MHz/640 MB
Product: 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!



Sponsored Link
Ads by Google

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

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


0

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

Many thanks,it is working perfectly!!


0

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

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

Mr. Adel


0

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

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


0

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

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


Mr. Adel


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Get first line from a file

Get last line from a file www.computing.net/answers/programming/get-last-line-from-a-file/15026.html

batch file - reading from a file www.computing.net/answers/programming/batch-file-reading-from-a-file/19110.html

To get the last 10 lines of a file. www.computing.net/answers/programming/to-get-the-last-10-lines-of-a-file/20114.html