How to print just the last line of a file?
because tail not fast as awk
yael
2010-06-20 19:51:15
@yael Not at all; `tail -1` will be way faster than `awk` for a large file. I tried on an ~3m line file; tail was instantaneous while awk took .44s
Michael Mrozek
2010-06-20 19:54:14
The `-1` form is deprecated. Use `tail -n 1`.
Dennis Williamson
2010-06-20 22:54:24
@yael. tail is specifically meant for processing the file from the "end". Therefore, its faster than awk. Because awk processes files from the beginning. The algorithms are different.
ghostdog74
2010-06-21 10:48:11
A:
if you must use awk then try
$ awk '
{X=$0}
END{print $0}' junk.lst
substitute your filename for junk.lst
josephj1989
2010-06-20 19:49:16
You probably meant `END {print X}` but it's not necessary to capture every line.
glenn jackman
2010-06-21 11:16:03
+2
A:
END{print}
should do it. Thanks to Ventero who was too lazy to submit this answer.
Joey
2010-06-20 19:49:59
+1
A:
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.
tail -1 file
If you really want to use awk,
awk 'END{print}' file
ghostdog74
2010-06-21 10:49:40