943,547 Members | Top Members by Rank

Ad:
Jul 24th, 2008
0

print only the last entry of the file

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
picass0 is offline Offline
45 posts
since Nov 2007
Jul 24th, 2008
1

Re: print only the last entry of the file

Shell Scripting Syntax (Toggle Plain Text)
  1. sed -n '$p' filename
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jul 24th, 2008
0

Re: print only the last entry of the file

thanks masijade! thanks for ur help!!!
Reputation Points: 10
Solved Threads: 0
Light Poster
picass0 is offline Offline
45 posts
since Nov 2007
Jul 24th, 2008
0

Re: print only the last entry of the file

Or
tail -1 file
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jul 24th, 2008
0

Re: print only the last entry of the file

^ Nice and simple, just the way I like it... though I'm more interested in the sed example.
Reputation Points: 13
Solved Threads: 9
Junior Poster in Training
omrsafetyo is offline Offline
58 posts
since Apr 2008
Jul 25th, 2008
0

Re: print only the last entry of the file

Click to Expand / Collapse  Quote originally posted by Salem ...
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. ;-)
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jul 25th, 2008
0

Re: print only the last entry of the file

sed will be slower than tail for huge files. Just a tip
Reputation Points: 75
Solved Threads: 44
Junior Poster
ghostdog74 is offline Offline
156 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: .sh to vbs
Next Thread in Shell Scripting Forum Timeline: check input arguments is upper or lower case





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC