LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 07-25-2006, 10:46 AM   #1
racingdynamics
LQ Newbie
 
Registered: Jul 2006
Posts: 1

Rep: Reputation: 0
SED Command


Can someone please tell me a way to display the last 3 lines of a file using the sed command?

Thanks in advance.
 
Old 07-25-2006, 10:58 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
It might be a lot easier for you to understand tail
Code:
tail -n3 file.txt
If you really have to use sed...
Code:
sed -e :a -e '$q;N;4,$D;ba' file.txt
 
Old 07-25-2006, 11:05 AM   #3
rickh
Senior Member
 
Registered: May 2004
Location: Albuquerque, NM USA
Distribution: Debian-Lenny/Sid 32/64 Desktop: Generic AMD64-EVGA 680i Laptop: Generic Intel SIS-AC97
Posts: 4,250

Rep: Reputation: 60
You're a jewel, homey, but you just did the guys homework for him. OTOH, I'd like to be there to hear his explanation when the instructor asks him just how that works. lol.
 
Old 07-25-2006, 01:03 PM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
I think that most questions are asking someone else to do the homework ( googling ) for them. At any rate, it seems alot of people would be happier if I didn't post at all.

It may be easier for a person to explain the use of tac which is cat from the bottom of the file...
Code:
tac < file.txt | sed -n '1,3p' | tac
 
Old 07-25-2006, 02:09 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
Originally Posted by rickh
You're a jewel, homey, but you just did the guys homework for him. OTOH, I'd like to be there to hear his explanation when the instructor asks him just how that works. lol.
My vast research shows that the sure sign of homework is when we never hear from the OP again.

My personal rule is to help if it looks like the individual has made an effort.

Note that many will tell you that we are not supposed to help with homework---not true. The forum rules only say that the requester should not EXPECT it.
 
  


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
sed command help... Pete.Hanson@jacobs.c Programming 8 06-02-2006 05:53 PM
sed command pazvant Linux - Software 2 05-09-2004 12:58 PM
sed command linuxdev Linux - Newbie 9 02-24-2004 04:50 PM
sed Command linuxdev Linux - Newbie 3 02-09-2004 11:27 AM
sed command kwigibo Linux - General 3 04-21-2002 04:11 PM


All times are GMT -5. The time now is 05:15 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration