开发者

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

开发者 https://www.devze.com 2023-03-27 08:51 出处:网络
What is the best way to output all lines of a file without the last line, using command-line tools? Example:

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

精彩评论

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