The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

tcgrep - search for regular expressions and print

SYNOPSIS

tcgrep [ -[incCwsxvhlF1HurtpaqT] ] [ -e pattern ] [ -f pattern-file ] [ -P sep ] [ pattern ] [ files ... ]

DESCRIPTION

tcgrep searches for lines (or, optionally, paragraphs) in files that satisfy the criteria specified by the user-supplied patterns. Because tcgrep is a Perl program, the user has full access to Perl's rich regular expression engine. See perlre.

The first argument after the options (assuming the user did not specify the -e option or the -f option) is taken as pattern. If the user does not supply a list of file or directory names to search, tcgrep will attempt to search its standard input.

With no arguments, tcgrep will output its option list and exit.

OPTIONS

tcgrep accepts these options:

-1

Allow at most one match per file.

-a

Search all files. The default is to only search plain text files and compressed files.

-C

Output the count of the matching lines or paragraphs. This is similar to the -c option (in fact, it implies the -c option), except more than one match is possible in each line or paragraph.

-c

Output the count of the matching lines or paragraphs.

-e pattern

Treat pattern as a pattern. This option is most useful when pattern starts with a - and the user wants to avoid confusing the option parser.

The -f option supercedes the -e option.

-F

fgrep mode. Disable regular expressions and perform Boyer-Moore searches. (Whether it lives up to the 'f' in fgrep is another issue).

-f pattern-file

Treat pattern-file as a newline-separated list of patterns to use as search criteria.

the -f option supercedes the -e option.

-H

Highlight matches. This option causes tcgrep to attempt to use your terminal's stand-out (emboldening) functionality to highlight those portions of each matching line or paragraph that actually triggered the match. This feature is very similar to the way the less(1) pager highlights matches. See also -u.

-h

Hide filenames. Only print matching lines or paragraphs.

-i

Ignore case while matching. This means, for example, that the pattern unix would match unix as well as UniX (plus the other fourteen possible capitalizations). This corresponds to the /i Perl regular expression switch. See perlre.

-l

List files containing matches. This option tells tcgrep not to print any matches but only the names of the files containing matches. This option implies the -1 option.

-n

Number lines or paragraphs. Before outputting a given match, tcgrep will first output its line or paragraph number corresponding to the value of the Perl magic scalar $. (whose documentation is in perlvar).

-P sep

Put tcgrep in paragraph mode, and use sep as the paragraph separator. This is implemented by assigning sep to Perl's magic $/ scalar. See perlvar.

-p

Paragraph mode. This causes tcgrep to set Perl's magic $/ to ''. (Note that the default is to process files in line mode.) See perlvar.

-q

Quiet mode. Suppress diagnostic messages to the standard error. See -s.

-r

Recursively scan directories. This option causes tcgrep to descend directories in a left-first, depth-first manner and search for matches in the files of each directory it encounters. The presence of -r implies a file argument of ., the current directory, if the user does not provide filenames on the command line. See "EXAMPLES".

-s

Silent mode. Do not write to the standard output. This option would be useful from a shell script, for example, if you are only interested in whether or not there exists a match for a pattern. See also -q.

-T

Trace files as processed. This causes tcgrep to send diagnostic messages to the standard error when skipping symbolic links to directories, when skipping directories because the user did not give the -r switch, when skipping non-plain files (see "-f" in perlfunc), when skipping non-text files (see "-T" in perlfunc), and when opening a file for searching

-t

Process directories in `ls -t` order. Search the files in each directory starting with the most recently modified and ending with the least recently modified.

-u

Underline matches. This option causes tcgrep to attempt to use your terminal's underline functionality to underline those portions of each matching line or paragraph that actually triggered the match. See also -H.

-v

Invert the sense of the match, i.e. print those lines or paragraphs that do not match. When using this option in conjunction with -f, keep in mind that the entire set of patterns are grouped together in one pattern for the purposes of negation. See "EXAMPLES".

-w

Matches must start and end at word boundaries. This is currently implemented by surrounding each pattern with a pair of \b, the Perl regular expression word boundary metasequence. See perlre for the precise definition of \b.

-x

Exact matches only. The pattern must match the entire line or paragraph.

ENVIRONMENT

The user's TCGREP environment variable is taken as the default set of options to tcgrep.

EXAMPLES

Search all files under /etc/init.d for a particular pattern:

    % tcgrep -r tcgrep /etc/init.d

Use of -v and -f options in conjunction with one another:

    % cat fruits
    pomme
    banane
    poire
    % cat pats
    pomme
    poire
    % tcgrep -vf pats fruits
    banane

TODO

  • Add more cool examples. :-)

  • Perhaps allow the user to provide an exclusion pattern for skipping over files whose names match the pattern.

REVISION HISTORY

    tcgrep: tom christiansen's rewrite of grep
    v1.0: Thu Sep 30 16:24:43 MDT 1993
    v1.1: Fri Oct  1 08:33:43 MDT 1993

    Revision by Greg Bacon <gbacon@cs.uah.edu>
    Fixed up highlighting for those of us trapped in terminfo
    implemented -f
    v1.2: Fri Jul 26 13:37:02 CDT 1996

    Revision by Greg Bacon <gbacon@cs.uah.edu>
    Avoid super-inefficient matching (almost twice as fast! :-)
    v1.3: Sat Aug 30 14:21:47 CDT 1997

    Revision by Paul Grassie <grassie@worldnet.att.net>
    Removed vestiges of Perl4, made strict
    v1.4: Mon May 18 16:17:48 EDT 1998

    Revision by Greg Bacon <gbacon@cs.uah.edu>
    Add fgrep functionality for PPT
    v1.5: Mon Mar  8 12:05:29 CST 1999

    Revision by Bill Benedetto <bbenedetto@goodyear.com>
    Added CLOSE after each file is done to reset counters
    v1.6: Sat Mar 20 23:05:35 1999

AUTHOR

tcgrep was written by Tom Christiansen with updates by Greg Bacon and Paul Grassie.

COPYRIGHT and LICENSE

Copyright (c) 1993-1999. Tom Christiansen.

This program is free and open software. You may use, copy, modify, distribute, and sell this program (and any modified variants) in any way you wish, provided you do not restrict others from doing the same.