Tommy has asked for the wisdom of the Perl Monks concerning the following question:
Are you forced to use a system grep without perl-compatible regex support? (i.e.- no "-P")
Let's say you want to grep a file for "foo", but not if it's proceeded by a comment "#" (with possible, legal leading whitespace). How would you grep for that on Unix with it's lame grep?
I turn to Perl. Can it be done without perl in one grep? Can this be done in Perl, but more simply? Show me!
Meanwhile, at the shell...
[[ "$( cat filename | perl -e 'print for grep { /^[[:space:]]{0,}#.+?f +oo/ } <>' )" != "" ]] && found_but_commented=1;
I guess I'm looking for a re-usable perl-construct to use as a grep substitute. Something along those lines above. Is there anything more easy than | perl -e 'print for grep { /regex/ } <>
Tommy
A mistake can be valuable or costly, depending on how faithfully you pursue correction
A mistake can be valuable or costly, depending on how faithfully you pursue correction
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Grep'ping on Unix without perl-compatible gnu grep - can you do it better?
by roboticus (Chancellor) on Feb 01, 2013 at 02:31 UTC | |
by Anonymous Monk on Feb 01, 2013 at 07:13 UTC | |
by parv (Parson) on Feb 01, 2013 at 07:37 UTC | |
Re: Grep'ping on Unix without perl-compatible gnu grep - can you do it better?
by kielstirling (Scribe) on Feb 01, 2013 at 02:35 UTC | |
by Tommy (Chaplain) on Feb 01, 2013 at 02:43 UTC | |
Re: Grep'ping on Unix without perl-compatible gnu grep - can you do it better?
by Tux (Canon) on Feb 01, 2013 at 07:37 UTC |
Back to
Seekers of Perl Wisdom