How to get the last line of a file using the cat command

I am writing a shell script in OSX (unix) environment. I have a file with a name test.propertieswith the following contents:

cat test.properties gets the following result:

//This file is intended for 
//blah blah purposes
123

Using the command cat, how can I get only the last line of the file?

+4
source share
2 answers

Do not use cat. tailIntended specifically for this utility:

$ tail -1 ./test.properties
+8
source

Not enough reputation to comment on a Mureinik post to answer your last question, but if you want to display a portion of the file between known lines, you can try sed -n '<line1>,<line2>p <filename>.

, tail sed: :

tail -r test.properties | sed -n '2p'
+2

Source: https://habr.com/ru/post/1658090/


All Articles