LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   SED Command (https://www.linuxquestions.org/questions/linux-general-1/sed-command-467475/)

racingdynamics 07-25-2006 10:46 AM

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.

homey 07-25-2006 10:58 AM

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

rickh 07-25-2006 11:05 AM

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.

homey 07-25-2006 01:03 PM

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

pixellany 07-25-2006 02:09 PM

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.


All times are GMT -5. The time now is 08:29 AM.