print only the last entry of the file

Reply

Join Date: Nov 2007
Posts: 45
Reputation: picass0 is an unknown quantity at this point 
Solved Threads: 0
picass0 picass0 is offline Offline
Light Poster

print only the last entry of the file

 
0
  #1
Jul 24th, 2008
i wanted to printout the last entry of the file without passing in any arguments but how can i able to do it? i know how to print out where argument is supplied and doing a grep to match it.

example inside the file i have:
apple:2:1:3
orange:1:2:3
grape:2:3:4

i wanted only to print out(last entry of my file):
grape:2:3:4
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,356
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: print only the last entry of the file

 
1
  #2
Jul 24th, 2008
Shell Scripting Syntax (Toggle Plain Text)
  1. sed -n '$p' filename
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 45
Reputation: picass0 is an unknown quantity at this point 
Solved Threads: 0
picass0 picass0 is offline Offline
Light Poster

Re: print only the last entry of the file

 
0
  #3
Jul 24th, 2008
thanks masijade! thanks for ur help!!!
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: print only the last entry of the file

 
0
  #4
Jul 24th, 2008
Or
tail -1 file
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 58
Reputation: omrsafetyo is an unknown quantity at this point 
Solved Threads: 9
omrsafetyo omrsafetyo is offline Offline
Junior Poster in Training

Re: print only the last entry of the file

 
0
  #5
Jul 24th, 2008
^ Nice and simple, just the way I like it... though I'm more interested in the sed example.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,356
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: print only the last entry of the file

 
0
  #6
Jul 25th, 2008
Originally Posted by Salem View Post
Or
tail -1 file
True. I like to give somewhat obscure answers to things that I belive are probably/possibly homework questions. That way, if they are not a homework question, the OP has something (s)he can use, and if they are, the teacher knows, as soon as (s)he sees it, that the student probably did not come up with it themselves. ;-)
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 148
Reputation: ghostdog74 is on a distinguished road 
Solved Threads: 40
ghostdog74 ghostdog74 is offline Offline
Junior Poster

Re: print only the last entry of the file

 
0
  #7
Jul 25th, 2008
sed will be slower than tail for huge files. Just a tip
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC