How to print just the last line of a file?
相关问题
- softlinks atime and mtime modification
- UNIX Bash - Removing double quotes from specific s
- Get unexpanded argument from bash command line
- Split a .txt file based on content
- Include and Execute EXE in C# Command Line App
相关文章
- Compile and build with single command line Java (L
- How to update command line output?
- How to execute another python script from your scr
- Python file keyword argument?
- How to detect EOF in awk?
- Interactively merge files tracked with git and unt
- Lauch default editor (like 'webbrowser' mo
- How to print jq output sequentially
Find out the last line of a file:
Using sed (stream editor):
sed -n '$p' fileName
Using tail:
tail -1 fileName
using awk:
awk 'END { print }' fileName
Is it a must to use
awk
for this? Why not just usetail -n 1 myFile
?should do it. Thanks to Ventero who was too lazy to submit this answer.
You can as well achieve this using
sed
. However, I personally recommend usingtail
orawk
.Anyways, if you wish to do by
sed
, here are two ways:Method 1:
Method2:
Here, filename is the name of the file that has data to be analysed.
Use the right tool for the job. Since you want to get the last line of a file, tail is the appropriate tool for the job, especially if you have a large file. Tail's file processing algorithm is more efficient in this case.
If you really want to use awk,
EDIT :
tail -1 file
deprecated