Hope others find "peg" as useful as it has been to me. Give it a try.
Announce - "peg", yet another (GNU) grep like Perl program.
The latest version is available at:
http://cpan.mirrors.uk2.net/authors/id/A/AD/ADAVIES/Features:
- Basic synopsis: peg [OPTION]... PERLEXPR [FILE]...
- Uses Perl expressions, NOT regular expression patterns.
eg% peg /needle/i haystack eg% peg "!(/^=\w/ .. /^=cut/) and /whatever/" *pm
These are identical:
eg% peg needle haystack eg% peg /needle/ haystack
eg% peg -inHC1Tm1 FOO words.txt words.txt-420- afloat words.txt:421: afoot words.txt-422- aforementioned
eg% cat haystack | peg -i needle
...searches the input stream, while
eg% peg -i needle
...recursively searches each file beneath the cwd.
eg% peg -p "/\.p[ml]$/i" -M 48h whatever
...looks in .pm & .pl files modified in the last 2 days.
Commonly used -p tests of file extensions can be defined:
$Peg_p{p} = 'pl:pm:t'; # peg_ini.pl
...and then used as:
eg% peg -p p -M 2d whatever
eg% peg -z "/^sub \w+/" foo *pm
...prints the last matched "sub" line for any lines matching "foo" ie. (probably) the subroutine that contains "foo".
Again, common 'contexts' can be defined:
$Peg_z{p} = '/^(?:\s*sub\s+\w|=head|__(?:END|DATA)__)/'; # peg_ini +.pl
...and then used as "-z p".
eg% peg chmod Temp.pm -nz p **** (331) sub _gettemp { 523: chmod(0600, $path); 545: chmod(0700, $path); **** (645) sub _force_writable { 647: chmod 0600, $file;
# peg_ini.pl $Peg_longopt{'ignore-dir'} = sub { my $argv_ref = shift; my $dir_name = shift @$argv_ref or die; unshift @$argv_ref, "-p", qq{ \$File !~ m:(^|/)$dir_name/: }; };
...would then enable
eg% peg foo --ignore-dir CVS
...to search for foo, ignoring all files in or beneath a directory called CVS.
As an optimization of the common case of doing a recursive search, an external program can be configured to feed peg the list of files beneath the current directory. The C program qfind.c which is also available at:
http://cpan.mirrors.uk2.net/authors/id/A/AD/ADAVIES/...is written specifically for this, and provides a significant speed up on Win32 compared to the default of traversing the file system with Perl's File::Find::find. Additionally peg performs parallel processing to maximize performance.