commands

grep — select matching lines

Selects matching text lines. -F uses literal strings, -E uses ERE, -n reports line numbers. Normally 0 match, 1 no match, 2 error; -q can mask an error when a match is found. Example assumes a fresh search-transform lab fixture.

Formal Syntax & Structure

linux syntaxlinux
grep [OPTION]... PATTERN [FILE]...

Parameters & Attributes

NameTypeDescription
-Foptionliteral pattern
-Eoptionextended regex
-noptionline numbers
PATTERNoperandsearch expression
FILEoperandinput file

Return Value

exit status and output

Selects matching text lines. -F uses literal strings, -E uses ERE, -n reports line numbers. Normally 0 match, 1 no match, 2 error; -q can mask an error when a match is found.

Working Example

Example Snippetlinux
grep -nF 'ERROR' events.log
Linux Reference