Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing lines at end of file 2

Status
Not open for further replies.

ddrillich

Technical User
Jun 11, 2003
546
US
Good Day,

I have a big text file that comes as a feed and I need to remove its last nine lines via a script and place them into a separate file.

Any ideas?

Many thanks,
Dan
 
[tt]tail -9 file1 > file2[/tt]
will put the last 9 lines of file1 into file2, but it won't remove them from file1.

Do you also want to change file1 in the process?

--
 
I need to remove its last nine lines via a script and place them into a separate file
echo "\$-8,\$w separatefile\n\$-8,\$d\nw\nq" | ed -s bigfile


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV,

Beautiful thing!!!

Can you please explain the script a bit?

Thank you PHV and Salem.
Dan
 
The script launch the ed program with the following list of commands:[tt]
$-8,$w separatefile [/tt]write the last 9 lines to separatefile[tt]
$-8,$d [/tt]delete the last 9 lines[tt]
w [/tt]update the original file[tt]
q [/tt]quit ed

Anyway:
man ed
man yourshell

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top