LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] sed question

[ILUG] sed question

John Allen john.allen at dublinux.net
Fri Feb 20 10:23:34 GMT 2004


On Friday 20 February 2004 09:13, Niall O Broin wrote:
> On Friday 20 February 2004, john.allen at dublinux.net (John Allen) wrote:
> >> Two characters less to type, and just a tiny bit less satisfying is:
> >>
> >>
> >> perl -ne 'if (/1^(2)/) {print} else { exit if $1}' humungous_file
> >
> >This one does not work though.
>
> That's right - I've no idea where the 1 after the / came from :-)
>
> However, the  whole thing is moot as Padraig is in a quest for speed, so
> the capture here is a bad idea (because it's relatively slow). Anyway, C
> and readline is probably the way he'll go. My Perl solution was written

Well I suppose it depends how far down the file the 2's are. If they are 
relatively near the top, it wouldn't make much difference. That said it would 
probably be just as fast in Perl with simpler pattern matching.

So with a quick rehash of Country Kev's script, I'd be surprised if C were any 
quicker.

perl -e 'while (<>) {
            last if ($_ eq "2")
        }
        print;
        while (<>) {
            exit if (!$_  eq "2");
            print
        }' file

> for conciseness and cuteness, not speed. And unlike a lot of Perl
> one-liners, it was understandable by mortals.
>
>
> Niall

-- 
John Allen,                          mailto:john.allen at dublinux.net
MandrakeClub Silver Member.          http://www.dublinux.net

Mandrake Linux release 10.0 (RC1) for i586, kernel 2.4.22-21mdk
 10:16:59 up 13 days, 18:02,  2 users,  load average: 0.19, 0.12, 0.09



More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell