How to display all lines of a file without the last line?

What is the best way to output all lines of a file without the last line using command line tools?

Example:

$ cat foo.txt abc vwxyz a sd dsgdfg $ some-cmd foo.txt abc vwxyz 
+4
source share
2 answers

BASH using head :

 $ head --lines=-1 filename 

Same thing for Mac:

 expr "$a" : '\(.*\) ' 

A new line is required!

+7
source

Probably the shortest way:

 sed '$d' filename 
+5
source

All Articles