Sed – How to Delete the Last Line from a File

sedtext processing

I use sed to quickly delete lines with specific position as

sed '1d'
sed '5d'

But, what if I want to delete the last line of the file and I don't know the count of lines (I know I can get that using wc and several other tricks).

Currently, using a workaround with head and tailcombined with wc to do so. Any quick twists here?

Best Answer

in sed $ is the last line so to delete the last line:

sed '$d' <file>
Related Question