|P is for Practical|
Equivalent of Linux Grep Commandby bichonfrise74 (Vicar)
|on Jul 13, 2009 at 19:05 UTC||Need Help??|
bichonfrise74 has asked for the
wisdom of the Perl Monks concerning the following question:
I'm trying to do a simple equivalent of
in Perl. This basically prints the previous and the next line when the word 'hello' is found. I've done a super search and came up with the following links:
Grep - print matched line and next N lines
Emulating GNU grep -A and -B switches with perl
Both were created back in 2003 and I was wondering if there is now a more concise solution to this. I mean using the Linux 'grep' command, it is able to do it in one line which strikes me odd that it cannot be done in Perl in a concise manner.
Below is my code but again, I think it is too clunky and too long when compared to the Linux 'grep' command.
Thanks in advance.