Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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
  • ...but automatically converts simple "string" expressions to "/string/".
  • These are identical:

    eg% peg needle haystack eg% peg /needle/ haystack
  • Supports, or has alternatives to, all the commonly used GNU grep options.
  • eg% peg -inHC1Tm1 FOO words.txt words.txt-420- afloat words.txt:421: afoot words.txt-422- aforementioned
  • If no files are specified, does The Right Thing
  • eg% cat haystack | peg -i needle

    ...searches the input stream, while

    eg% peg -i needle

    ...recursively searches each file beneath the cwd.

  • Is configurable through variables set in a configuration file "peg_ini.pl".
  • Options to restrict files searched based on name and last modification time.
  • 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
  • The "-z" option prints 'context'.
  • 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;
  • Customizable command line options.
  • # 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.

  • Windows friendly - does filename globbing.
  • Coloured output. (On Win32, this requires Win32::Console::ANSI.)
  • Fast find...
  • 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.

  • Can read and write encoded data.
  • Lots more options. See the "-help".

In reply to peg - Perl _expression_ (GNU) grep script by Clarendon4

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-03-19 03:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found