glark - Search text files for complex regular expressions glark [options] expression file ... Similar to `grep', `glark' offers: Perl-compatible regular expressions, color highlighting of matches, context around matches, complex expressions ("and" and "or"), grep output emulation, and automatic exclusion of non-text files. Its regular expressions should be familiar to persons experienced in Perl, Python, or Ruby. Display the help message. Print NUM lines after a matched expression. Print NUM lines before a matched expression. Output <NUM> lines of context around a matched expression. The default is no context. If no NUM is given for this option, the number of lines of context is 2. Instead of normal output, display only the number of matches in each file. Directories are processed according to the given ACTION, which by default is 'read'. If ACTION is 'recurse', each file in the" directory is read and each subdirectory is recursed into (equivalent to the -r option). If ACTION is 'skip', directories are not read, and no message is produced. Specify the highlight color for file names. See the HIGHLIGHTING section for more information. Produce output like the grep default: file names and line numbers, and a single line of the match, which will be the first line for matches that span multiple lines. Do not display the names of the files that matched. Display the names of the files that matched. This is the default behavior. Match regular expressions without regard to case. The default is case sensitive. Print only the names of the file that matched the expression. Print only the names of the file that did not match the expression. Display the line numbers. This is the default behavior. Do not display the line numbers. Suppress warnings. Enable warnings. This is the default. Recurse through directories. Equivalent to --directories=read. Specify the highlight color for text. See the HIGHLIGHTING section for more information. Turn highlighting on, which uses ANSI escape sequences. This is the default behavior. The '-hl' option is deprecated. See the HIGHLIGHTING section for more information. Turn highlighting off. The '-nohl' option is deprecated. Show lines that do not match the expression. Display version information. Put word boundaries around each pattern, thus matching only where the full word(s) occur in the text. Thus, glark -w Foo is the same as glark '/\bFoo\b/'. Do not put word boundaries around each pattern. This is the default. Select only where the entire line matches the pattern(s). Do not select only where the entire line matches the pattern(s). This is the default behavior. When in -l mode, write file names followed by the ASCII NUL character ('\0') instead of '\n'. Display normally suppressed output, for debugging purposes.

Regular Expressions
Regular expressions are expected to be in the Perl/Ruby format. Run `perldoc perlre' for more general information. The expression may be of either form: something /something/ There is no difference between the two forms, except that with the latter, one can provide the "ignore case" modifier, thus matching "someThing" and "SoMeThInG": % glark /something/i Note that this is redundant with the "-i" ("--ignore-case") option. All regular expression characters and options are available, such as "\w", ".*?" and "[^9]". For example: % glark '\b[a-z][^\d]\d{1,3}.*\s*>>\s*\d+\s*.*& +\d{3}' If the and and or options are not used, the last non-option is considered to be the expression to be matched. In the following, "printf" is used as the expression. % glark -w printf *.c POSIX character classes (e.g., [[:alpha:]]) are also supported.

Complex Expressions
Complex expressions combine regular expressions (and complex expressions themselves) with logical AND and OR operators. Matches either of the two expressions. The results of the two forms are equivalent. In the latter syntax, the --end-of-or is optional. Matches both of the two expressions, within <number> lines of each other. As with the or option, the results of the two forms are equivalent, and the --end-of-and is optional. If the number provided is -1 (negative one), the distance is considered to be "infinite", and thus, the condition is satisfied if both expressions match within the same file. If the number provided is 0 (zero), the condition is satisfied if both expressions match on the same line. A warning will be issued if the value given in the number position does not appear to be numeric. This option writes the expression in a more legible format. It can useful for debugging. Matching patterns and file names can be highlighted using ANSI escape sequences. Both the foreground and the background colors may be specified, from the following: black blue cyan green magenta red white yellow The foreground may have any number of the following modifiers applied: blink bold concealed reverse underline underscore The format is "MODIFIERS FOREGROUND on BACKGROUND". For example: red (default background) green on white bold underline red on cyan By default text is highlighted as black on yellow. File names are written in reversed bold text. % glark format *.h Searches for "format" in the local .h files. % glark -i format *.h Searches for "format" without regard to case. % glark -6 format *.h Produces 6 lines of context around any match for "format". % glark -o format print *.h Searches for either "printf" or "format". % glark -a 4 printf format *.c *.h Searches for both "printf" or "format" within 4 lines of each other. % glark -3 -a 0 printf format *.c Searches for both "printf" or "format" on the same line ("within 0 lines of each other"). Three lines of context are displayed around any matches. % glark -8 -i -a 15 -a 2 pthx '\.\.\.' -o 'va_\w+t' die *.c (In order of the options:) Produces 8 lines of context around case insensitive matches of ("phtx" within 2 lines of '...' (literal)) within 15 lines of (either "va_\w+t" or "die"). % glark -a -1 '#define\s+YIELD' '#define\s+dTHR' *.h Looks for "#define\s+YIELD" within the same file (-1 == "infinite distance") of "#define\s+dTHR". % glark -l '\b\w{25,}\b' *.c Displays (only) the names of the files that contain "words" at least 25 characters long. % glark -L '"\w+"' Displays (only) the names of the files that do not contain strings consisting of a single word. % glark -T "red on white" '\b[[:digit:]]{5}\b' *.c Display (in red text on a white background) occurrences of exactly 5 digits. A string of whitespace-delimited options. Due to parsing constraints, should probably not contain complex regular expressions. A resource file, containing name/value pairs, separated by either ':' or '='. The valid fields of a .glarkrc file are as follows, with example values: after-context: 1 before-context: 6 context: 5 file-color: blue on yellow highlight: off ignore-case: false quiet: yes text-color: bold reverse verbose: false "yes" and "on" are synonymnous with "true". "no" and "off" signify "false". The counterpart for the --grep option is the "grep" resource file field, for example: grep: true

Exclusion of Non-Text Files
Non-text files are automatically skipped, by taking a sample of the file and checking for an excessive number of non-ASCII characters. In the code, see `@@KNOWN_TEXT' and `@@KNOWN_NONTEXT' for the extensions of files that are presumed to be text and nontext, and are not subjected to this test. For regular expressions, the `perlre' man page. Mastering Regular Expressions, by Jeffrey Friedl, published by O'Reilly. "Unbalanced" leading and trailing slashes will result in those slashes being included as characters in the regular expression. Thus, the following pairs are equivalent: /foo "/foo" /foo\/ "/foo/" /foo\/i "/foo/i" foo/ "foo/" foo/ "foo/" The code to detect nontext files assumes ASCII, not Unicode. The exit status is 0 if matches were found; 1 if no matches were found, and 2 if there was an error. An inverted match (the -v/--invert-match option) will result in 1 for matches found, 0 for none found. Jeff Pace <jpace@glark.org> Copyright (c) 2002, Jeff Pace. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the terms of the Lesser GNU Public License. See http://www.gnu.org/licenses/lgpl.html for more information.