logo       

Re: sed one-liner?: msg#00071

editors.sed.user

Subject: Re: sed one-liner?

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>
Google Custom Search

News | FAQ | advertise