How to output 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
a b c
v w x y z
a sd dsgdfg
开发者_StackOverflow社区$ some-cmd foo.txt
a b c
v w x y z
BASH, using head
:
$ head --lines=-1 filename
Same for Mac:
expr "$a" : '\(.*\)
'
The newline is required!
Probably the shortest way:
sed '$d' filename
精彩评论