Difference between revisions of "Grep"
Jump to navigation
Jump to search
Line 2: | Line 2: | ||
;grep <pattern> <files> | ;grep <pattern> <files> | ||
− | :Find pattern in any of the files. | + | :Find lines matching pattern in any of the files. |
:When multiple files are scanned the filename is reported too (see -h below) | :When multiple files are scanned the filename is reported too (see -h below) | ||
− | + | =Useful options= | |
;-i | ;-i | ||
− | :Ignore case | + | :Ignore case |
+ | ;-v | ||
+ | :Negate the match, show all lines not having the pattern | ||
;-l | ;-l | ||
:Only report filename of files with matches | :Only report filename of files with matches | ||
Line 16: | Line 18: | ||
;-f <file> | ;-f <file> | ||
:Get patterns from <file>. One(1) pattern per line. | :Get patterns from <file>. One(1) pattern per line. | ||
+ | |||
+ | =Return value ( $? )= | ||
+ | 0 (true) if one or more matches are found | ||
+ | |||
+ | 1 (false) if no matches are found |
Revision as of 21:58, 21 November 2018
Find pattern in data stream (files, standard input)
- grep <pattern> <files>
- Find lines matching pattern in any of the files.
- When multiple files are scanned the filename is reported too (see -h below)
Useful options
- -i
- Ignore case
- -v
- Negate the match, show all lines not having the pattern
- -l
- Only report filename of files with matches
- -h
- Suppress reporting of filenames when multiple files are scanned.
- -n
- Report linenumber of matches too
- -f <file>
- Get patterns from <file>. One(1) pattern per line.
Return value ( $? )
0 (true) if one or more matches are found
1 (false) if no matches are found