开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜