LinuxCommandLibrary

grap

Search files for specific patterns

TLDR

Process a grap file and save the output file for future processing with pic and groff

$ grap [path/to/input.grap] > [path/to/output.pic]
copy

Typeset a grap file to PDF using the [me] macro package, saving the output to a file
$ grap [path/to/input.grap] | pic -T [pdf] | groff -[me] -T [pdf] > [path/to/output.pdf]
copy

SYNOPSIS

grep [OPTIONS] PATTERN [FILE...]

PARAMETERS

PATTERN
    The regular expression or string to search for.

FILE...
    One or more files to search. If no files are specified, grep reads from standard input.

-i, --ignore-case
    Ignore case distinctions in both the PATTERN and the input files.

-v, --invert-match
    Select non-matching lines.

-n, --line-number
    Prefix each line of output with the line number within its input file.

-c, --count
    Suppress normal output; instead print a count of matching lines for each input file.

-r, -R, --recursive
    Recursively search directories.

-l, --files-with-matches
    Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match.

-o, --only-matching
    Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.

-w, --word-regexp
    Select only those lines containing matches that form whole words.

-E, --extended-regexp
    Interpret PATTERN as an extended regular expression (ERE).

-F, --fixed-strings
    Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched.

DESCRIPTION

The grep command is a powerful text searching utility available on Linux and other Unix-like operating systems.

It searches input files for lines containing a match to a specified pattern. By default, grep prints the matching lines to standard output. The pattern can be a string literal or a regular expression, allowing for flexible and complex searches. Grep offers a wide variety of options to control its behavior, including case-insensitive matching, inverting the match, displaying line numbers, and more. It's an indispensable tool for developers, system administrators, and anyone who needs to find specific information within text files.

It's important to understand Regular Expressions to leverage the command to its maximum.

Grep stands for "Globally search a Regular Expression and Print".

CAVEATS

Regular expressions can be complex and require careful construction to avoid unintended matches. Performance can degrade significantly when searching very large files or using overly complex regular expressions.

EXIT STATUS

The grep command exits with status 0 if a line is selected, 1 if no lines were selected, and 2 if an error occurred.

REGULAR EXPRESSION METACHARACTERS

Grep supports several metacharacters in regular expressions, including . (any character), * (zero or more occurrences), + (one or more occurrences, with -E), ? (zero or one occurrence, with -E), [] (character class), ^ (beginning of line), and $ (end of line).

HISTORY

Grep was originally developed for the Unix operating system in the early 1970s by Ken Thompson as a standalone utility. It's based on a command in the ed line editor called 'g/re/p' (globally search a regular expression and print). Grep has become a ubiquitous tool in Unix-like environments and is now part of the POSIX standard.

SEE ALSO

sed(1), awk(1), find(1)

Copied to clipboard