incava.org

A replacement for (or supplement to) the grep family, glark offers: Perl compatible regular expressions, highlighting of matches, context around matches, complex expressions (``and'' and ``or''), and automatic exclusion of non-text files.

Highlighting

In default mode, glark highlights matches and file names, for example:

% glark '=\s*rb_v?sprintf' *.c

On a subset of the Ruby source code, this produces:

example output

Colors can be customized by settings in a configuration file (~/.glarkrc), an environment variable (GLARKOPTS), or the command line.

Perl Compatible Regular Expressions

glark provides the ability to use Perl compatible regular expressions (PCRE), which should be familiar to users of Perl, PHP, and Ruby. For example, this searches for a word boundary, followed by "val", not followed by "ue":

% glark '\bval(?!ue)' *.c

PCRE documentation can be found here.

Compound Expressions

Regular expressions can be combined into complex expressions that span multiple lines, such as the following, which searches for "printStackTrace" within 2 lines of "catch":

% glark --and=2 printStackTrace catch *.java

To search for either "catch" or "throw" on the same line:

% glark --or catch throw *.java

This searches for "cout" or "printf", within 5 lines of either "double" or "float":

% glark --and=5 --or cout print --or double float *.c

Detection of Text Files

Files that are not text are not searched, by default.

Compatibility with GNU grep

glark supports nearly all of the options in the GNU version of grep.

Multi-Platform

glark is written in Ruby, and thus can run on a variety of operating systems, including Windows and Unix variants.

Ranges

The --before and --after options restrict searching to the top or end of the file, useful, for example for searching mail headers.

See Examples for more examples.

Valid HTML 4.01!

Valid CSS!