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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete last line from text file

Status
Not open for further replies.

gfunk123

IS-IT--Management
May 22, 2001
143
GB

I have a file with which i must remove the last line of the file (the footer). I know how to copy and redirect with tail -1 etc, but how do i delete it permanentely

cheers
 
With sed you can do the following:

$ sed '$d' original_file > file_without_last_line

Then you still have the original one if you need it.
In the file_without_last_line you have the desired result.

mrjazz [pc2]
 
To update the file in place, you could use the ex editor.
Code:
ex - file1 << EOF
$d
wq
EOF
Hope this helps. CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top