|
Re: sed one-liner?: msg#00071editors.sed.user
Replying to Lori Barfield, who sent me this message: > On 12/15/05, William Yardley <uuasc@xxxxxxxxxxxxxxxxx> wrote: > > Anyone know a one-liner to print the next to last line in sed? [ ... ] > On 12/19/05, Philip Brown <phil@xxxxxxxxxxxx> wrote: > > > sed -n -e '/^.*$/x' -e '$p' > > what an elegant answer. since Mark threw down the gauntlet, i had to > give this a try myself. I decided to give it a try also. The following sed script will print the penultimate line (the next to last line) on a file of any length except a file which has only one line, in which case it prints nothing: sed -e '$!{h;d;};x' I think I'll add it to the next edition of the sed one-liners page, unless anyone comes up with something better. -- Eric Pement ------------------------ Yahoo! Groups Sponsor --------------------~--> AIDS in India: A "lurking bomb." Click and help stop AIDS now. http://us.click.yahoo.com/9QUssC/lzNLAA/TtwFAA/dkFolB/TM --------------------------------------------------------------------~-> -- Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/sed-users/ <*> To unsubscribe from this group, send an email to: sed-users-unsubscribe@xxxxxxxxxxxxxxx <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/ |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | sed pattern recognition with consecutive lines: 00071, grendelos |
|---|---|
| Next by Date: | Re: sed pattern recognition with consecutive lines: 00071, Eric Pement |
| Previous by Thread: | sed pattern recognition with consecutive linesi: 00071, grendelos |
| Next by Thread: | Re: sed one-liner?: 00071, Angus Leeming |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |