LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-24-2007, 07:46 PM   #1
Micro420
Senior Member
 
Registered: Aug 2003
Location: Berkeley, CA
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986

Rep: Reputation: 45
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!
 
Old 01-24-2007, 08:18 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Here are a couple that just may work for you.
Code:
sed -n '$p' file.txt
and
tail -n1 file.txt
 
Old 01-24-2007, 09:24 PM   #3
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
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
do
tail -n1 >> lastline.txt
done

to print the last lines to file lastline.txt.

Last edited by bigrigdriver; 01-24-2007 at 09:25 PM.
 
Old 01-25-2007, 01:17 AM   #4
Micro420
Senior Member
 
Registered: Aug 2003
Location: Berkeley, CA
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986

Original Poster
Rep: Reputation: 45
DOh! I totally forgot about the head and tail command. That should work! Thanks y'all
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
print a text file with long lines and line number added powah Linux - General 2 05-26-2006 02:02 PM
command line edit -- global find/replace on text file w/o going into vi car182 Linux - Newbie 4 05-25-2006 05:42 PM
command or shell script to print line range from file minil Programming 3 12-28-2005 08:05 AM
Passing a text file to the command line as arguments wimnat Linux - General 2 12-05-2005 08:09 AM
chpasswd from a command line (without a text file) mpgram Linux - Security 1 04-18-2004 05:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration