App-Gre
view release on metacpan or search on metacpan
* can be further modified by adding no, i, e, r, x
=head1 DESCRIPTION
This grep clone is capable of filtering file names as well as file
contents with regexps. For example if you want to search all files
whose name contains "bar" for the string "foo", you could write
this:
$ gre -name=bar foo
Only .c files:
$ gre -ext=c foo
You can build up arbitrarily complex conditions to just search the
files you want:
$ gre -ext=html -noext=min.html foo
This would find "foo" in all .html files that aren't .min.html files.
=head1 FILE FILTERING
When your command line doesn't include a regexp (or is the empty
string), the gre program will list files that would be searched.
The standard "include" filters are done in order left to right. This:
$ gre -perl -php
will list all perl and php files. This:
$ gre -perl -noname=foo -php
will list all perl files, remove those whose name matches the regexp
of foo, then add all php files. Order counts. Those php files might
have "foo" in their name. If you want all perl and php files whose
name doesn't match "foo", you need this:
$ gre -perl -php -noname=foo
The first option can either add files to the set of nothing or remove files
from the set of all. For example:
$ gre -perl
will only show perl files.
$ gre -noperl
will show all files except perl files.
There are two levels of filtering that run independent of each
other. One level is the "include" filters like -perl, -nophp, or
-ext=c. The second level is the "exclude" filters like -xname=foo
or -xbinary.
Why are they independent? Consider if the script had a default
filter to remove all backup files (-xname='~$') which would have
to mix with additional command line filters. The following would
try to search for bash files (files whose first line starts with
#!/bin/bash) that aren't backups:
$ gre -xname='~$' -line1='^#!/bin/bash'
It wouldn't work if they weren't independent: filters are additive,
so this would have added all files which are not backups then add
all files which are bash files (some of which may be backup files).
The reason the filters have to be additive is to let commands like
this work:
$ gre -html -js
which will find all html and javascript files.
If I added the builtin filters after the command line arguments:
$ gre -line1='^#!/bin/bash' -xname='~$'
Then you wouldn't have a chance to disable it:
$ gre -line1='^#!/bin/bash' -noxname='~$' -xname='~$'
It would still filter out the backup files.
The result should be intuitive. For example, if you want to
search everything except one file that's messing up the search add:
$ gre -xname=INBOX.mbox -ext=mbox qwerty
and you wouldn't have to worry about order of these filters.
If you want to remove all the builtin "exclude" filters, use -x on
the command line. By default, gre will exclude backup files, swap
files, core dumps, .git directories, .svn directories, binary files,
minimized js files, and more. See the output of -c for the full
list.
"exclude" filters also have another property which the regular
"include" filters don't have: They prune the recursive file search.
So -xnamee=.git will prevent any file under a .git directory from
being searched (the extra e at the end of -xname means to use
string equality not regexp's for the match). Normal "include"
filters do not execute on directories.
You can control the depth of the recursion with the -d option. -d0
is for unlimited recursion (the default), -d1 disables recursion,
-d2 will only let recursion go two levels deep.
Files listed on the command line are always searched regardless of
the filters.
Symlinks are not followed. This is usually what you want and otherwise
you might end up in an infinite loop.
You can do multiline regexp's '^sub.*^\}' (with the addition of the
-m option)
The script doesn't bundle options so it only uses one dash for the
long options.
Options that take arguments can be given like -ext=foo or -ext foo.
Option names for file filters can include:
=over
=item * "no" filters files out,
=item * "i" makes the regexp case insensitive,
=item * "e" makes the match use string equality instead of regexp,
=item * "r" makes the match use regexp instead of string equality,
=item * "x" makes it an excluding filter
=back
=head1 OUTPUT STYLES
You can specify the output style with the -y option:
-y1 groups output by filename, with each matching line prepended
with it's line number. This is the default.
-y2 looks like classic grep output. Each line looks like file:line:match.
-y3 just has the matching line. This is the default for piped input.
goes well with the -p option sometimes.
-k will disable color output.
-o will show only the match (as opposed to the entire matching line).
( run in 0.857 second using v1.01-cache-2.11-cpan-39bf76dae61 )