Nguyễn Ngọc Tâm Quyên
Member
How do you remove the last line of a file in Unix?
Answer
So sed ‘$d’ file; sed ‘$d’ file will print out the contents of the file twice, minus the last line each time. The delete-the-last-two-lines equivalent of sed ‘$d’ file is
sed ‘$d’ file | sed ‘$d’. Yeah, that’s inelegant but of course it works.
Answer
So sed ‘$d’ file; sed ‘$d’ file will print out the contents of the file twice, minus the last line each time. The delete-the-last-two-lines equivalent of sed ‘$d’ file is
sed ‘$d’ file | sed ‘$d’. Yeah, that’s inelegant but of course it works.