|
Re: sed one-liner?: msg#00073editors.sed.user
Eric Pement wrote: > 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' How about adding 1{ ${ p q } } To overcome that limitation? Angus ------------------------ Yahoo! Groups Sponsor --------------------~--> Fair play? Video games influencing politics. Click and talk back! http://us.click.yahoo.com/2jUsvC/tzNLAA/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: | Re: sed pattern recognition with consecutive lines: 00073, Eric Pement |
|---|---|
| Next by Date: | penultimate line script: 00073, pemente |
| Previous by Thread: | Re: sed one-liner?i: 00073, Eric Pement |
| Next by Thread: | penultimate line script: 00073, pemente |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |