develooper Front page | perl.beginners | Postings from December 2002

GNU grep -C in Perl

Thread Next
From:
Jerry Rocteur
Date:
December 10, 2002 12:23
Subject:
GNU grep -C in Perl
Message ID:
1F2A15D2-0C7D-11D7-8FA3-003065E76B5E@rocteur.cc
Hi,

Anyone know how to write a grep -C in Perl ?

You know, I want to search for a string/regexp in a file and I want to 
print the line before and the line after the search string.

I've tried a couple of ways and it takes a really long time, I load the 
file in memory, seach for the string, extract the line number of the 
string $. subtract one and add one and print the three lines but this 
can take a very long time.. I don't have grep -C on the system I want 
to do this.

I've looked at perldoc and the list archives and can't fing any help..

Thanks in advance,

Jerry


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About