Computing.Net > Forums > Unix > Get the 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 the first line from a file

Reply to Message Icon

Name: Raj81508
Date: December 10, 2007 at 21:06:05 Pacific
OS: Unix
CPU/Ram: Intel P4, 1 GB Ram
Comment:

Hi All,
I want to get the first line from a file and write it into another file.
Please help. Thanks in advance.
Regards,
Raj


Thanks & Regards,
Raj



Sponsored Link
Ads by Google

Response Number 1
Name: lankrypt0
Date: December 11, 2007 at 08:01:37 Pacific
Reply:

head -1 infile.txt > outfile.txt


0

Response Number 2
Name: nails
Date: December 11, 2007 at 22:19:16 Pacific
Reply:

If you don't like the 'head' example, there's always sed:

sed q infile.txt > outfile.txt

or awk:

awk ' { if(NR == 1)
{
print $0
break
}
} ' infile.txt > outfile.txt


0

Response Number 3
Name: FishMonger
Date: December 12, 2007 at 16:21:44 Pacific
Reply:

Or perl

perl -pe "last if $. == 2" input.txt > output.txt


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Get the first line from a file

Delete first line of a file www.computing.net/answers/unix/delete-first-line-of-a-file/7594.html

how to get the modified time of a file www.computing.net/answers/unix/how-to-get-the-modified-time-of-a-file/2110.html

extract a specific line from file www.computing.net/answers/unix/extract-a-specific-line-from-file/5381.html