A command-line utility for searching for regular expressions, which uses Perl regular expressions, which I made because the version of grep
that comes with my computer (Mac OS X) doesn't support Perl-style regular expressions. It requires Perl (at least version 5.16.2 works). Its flags are not all compatible with other versions of grep
. It's unrelated to any other programs with this name.
Download plgrep (10.85K) (source)
(This is for version 3; for earlier versions use --help
.)
Basic syntax:
plgrep [-AcHhilLnruz -Iglob -Xglob --binary-files=(ignore|binary|text) --exclude-dir=glob --follow-links --max-chars=n --section=pattern --section-after=pattern] pattern [file ...]
plgrep [options] -e pattern [-e pattern ...] [-v pattern ...] [file ...]
plgrep [options] -v pattern [-v pattern ...] [file ...]
-H
, --with-filename
-h
, --no-filename
-n
, --line-number
-c
, --color
, --colour
-l
, --files-with-matches
-L
, --files-without-match
--max-chars=n
--section=pattern
--section='^\S'
(i.e., previous unindented line) or --section='^[^\s{]'
(i.e., previous unindented line that doesn't start with an open brace) will display which function the match is in; or --section='<h2>'
will display the previous level-2 heading in an HTML file.
--section-after=pattern
--section
, except the line displayed is the one after the one matched. For instance, if a document is divided into sections separated by blank lines, --section-after='^$'
displays the first line of the section.
--binary-files=(ignore|binary|text)
ignore
: pretend they don't exist
binary
: display a message including the byte offset that matched (this is the default)
text
: treat them as if they were text
-z
, --compressed-text
.tgz
files are also treated as compressed text (which can work if the contents of the archive is text).
-u
, --utf-8
-r
, -R
, --recursive
-r
is implied. If -r
is specified or implied and no explicit filename is given on the command line, defaults to searching the current directory rather than the standard input.
--follow-links
.
). Not specifying this option is equivalent to specifying --exclude=.* --exclude-dir=.*
.
-I
, --include=glob
*
= any number of characters, ?
= one character, and character classes can also be used)
-X
, --exclude=glob
--exclude-dir=glob
-e pattern
-v pattern
, --invert-match=pattern
-e
and -v
(non-matches always take precedence over matches). Note that this is not quite the same as normal grep -v
: plgrep
's -v
takes the pattern as an argument, so plgrep -vi pattern
searches for the lines not containing "i" in the file "pattern", rather than searching case-insensitively for lines not containing "pattern" in the standard input; for the latter interpretation, make -v
the last option (plgrep -iv pattern
).
-i
, --ignore-case
--help
plgrep --help | less
). (Help displayed when you forget to type a pattern is displayed on standard error.)
--version
.gz
, .bz2
) files (-z
option)
-u
option)
-v
take a pattern argument, thus allowing "and not" queries.
--max-chars
option to limit the number of characters displayed per line
--section
and --section-after
flags, which could be useful when dealing with files that have some concept of a "section" (including code files, where a function can be considered a section)
--help
to standard output, for easier piping to less
or more
.
pgrep
to plgrep
, since pgrep
is apparently already taken on some systems as a tool for searching for running processes. (That command wasn't on the computer where I initially wrote this program.) A Google search shows there are also programs named plgrep
, at least two of which do the same thing this program does, but the fact that there are at least two suggests that the name isn't reserved for one particular implementation or anything.
--follow-links
wasn't specified)