Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

text

shell

unix

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 

$ some-cmd foo.txt
a b c
v w x y z
like image 617
Frank Avatar asked Dec 17 '22 10:12

Frank


1 Answers

BASH, using head:

$ head --lines=-1 filename

Same for Mac:

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

The newline is required!

like image 198
Dor Avatar answered Jan 10 '23 15:01

Dor