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 ?
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.
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.
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.
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.
Don't use cat
. tail
was meant for this usecase exactly:
$ tail -1 ./test.properties
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With