-   Linux - General (
-   -   Command to print last line of a text file (

Micro420 01-24-2007 07:46 PM

Command to print last line of a text file
I'm stumped, but I am trying to think of a way to print only the last line of some files that have time results at the end of them. Can `sed` or `grep` do any of these? I'm sure they can, but I am not familiar with the options.

The files have no fixed length and nothing in common. If I can just print the last line of each file, then I am set! Any suggestions would be helpful!

homey 01-24-2007 08:18 PM

Here are a couple that just may work for you.

sed -n '$p' file.txt
tail -n1 file.txt

bigrigdriver 01-24-2007 09:24 PM

If you have just a few files to print the last line, you could try:

touch lastline.txt
for i in file1.txt file2.txt file3.txt
tail -n1 >> lastline.txt

to print the last lines to file lastline.txt.

Micro420 01-25-2007 01:17 AM

DOh! I totally forgot about the head and tail command. That should work! Thanks y'all

All times are GMT -5. The time now is 06:35 AM.