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

MacosShellUnixCat

Macos Problem Overview


I am writing a shell script in OSX(unix) environment. I have a file called test.properties with the following content:

cat test.properties gets the following output:

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

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

Macos Solutions


Solution 1 - Macos

Don't use cat. tail was meant for this usecase exactly:

$ tail -1 ./test.properties

Solution 2 - Macos

Don't have enough reputation to comment Mureinik's post to answer your last question, but if you want to display a part of a file between known lines, you can try sed -n '<line1>,<line2>p <filename>.

If you don't know the lines, mix tail and sed : For your file :

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTheWaterProgrammerView Question on Stackoverflow
Solution 1 - MacosMureinikView Answer on Stackoverflow
Solution 2 - MacosTheo PnvView Answer on Stackoverflow