GREP(1)

NAME

grep - print lines that match patterns

SYNOPSIS

grep [OPTIONS] PATTERN [FILE...]

DESCRIPTION

grep searches input files for lines that match a given pattern. By default, it prints the matching lines to standard output.

Patterns are interpreted as basic regular expressions unless otherwise specified.

OPTIONS

-i, --ignore-case
Ignore case distinctions in patterns and input data.
-r, --recursive
Read all files under each directory recursively.
-n
Prefix each line of output with the line number.
-v, --invert-match
Select non-matching lines.
-c, --count
Print only a count of matching lines per file.
-l
Print only names of files with matches.

EXAMPLES

# Search for "error" in a file
grep "error" logfile.txt

# Case-insensitive search
grep -i "warning" logfile.txt

# Recursive search in a directory
grep -r "TODO" ./src

# Show line numbers
grep -n "main" program.c
    

EXIT STATUS

0 if a match is found, 1 if no matches are found, and 2 if an error occurred.

SEE ALSO

egrep, fgrep, sed, awk

AUTHOR

Originally written by GNU Project contributors.