Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 689
TheWaterProgrammer Avatar asked Oct 18 '16 12:10

TheWaterProgrammer


People also ask

How do I display the last line of a file?

Use the tail command to write the file specified by the File parameter to standard output beginning at a specified point. This displays the last 10 lines of the accounts file. The tail command continues to display lines as they are added to the accounts file.

How do you go to the last line of a file in Linux?

In short press the Esc key and then press Shift + G to move cursor to end of file in vi or vim text editor under Linux and Unix-like systems.

How do you finish a cat command?

Making cat Read From stdin This is because the cat command is now listening to the standard input. We can see that whatever texts we've entered into the standard input stream will be echoed to the output stream by the cat command. Once we are done, we can terminate the command by pressing CTRL+D.

What is cat << end?

This operator stands for the end of the file. This means that wherever a compiler or an interpreter encounters this operator, it will receive an indication that the file it was reading has ended.


Video Answer


1 Answers

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

$ tail -1 ./test.properties 
like image 61
Mureinik Avatar answered Sep 28 '22 03:09

Mureinik