2025-03-14 21:59:59 -06:00
|
|
|
# egrep
|
|
|
|
|
|
|
|
|
|
> Find patterns in files using extended regular expression (supports `?`, `+`, `{}`, `()`, and `|`).
|
|
|
|
|
> More information: <https://manned.org/egrep>.
|
|
|
|
|
|
|
|
|
|
- Search for a pattern within a file:
|
|
|
|
|
|
|
|
|
|
`egrep "{{search_pattern}}" {{path/to/file}}`
|
|
|
|
|
|
|
|
|
|
- Search for a pattern within multiple files:
|
|
|
|
|
|
|
|
|
|
`egrep "{{search_pattern}}" {{path/to/file1 path/to/file2 ...}}`
|
|
|
|
|
|
|
|
|
|
- Search `stdin` for a pattern:
|
|
|
|
|
|
|
|
|
|
`cat {{path/to/file}} | egrep {{search_pattern}}`
|
|
|
|
|
|
|
|
|
|
- Print file name and line number for each match:
|
|
|
|
|
|
2025-05-08 12:26:01 -06:00
|
|
|
`egrep {{[-H|--with-filename]}} {{[-n|--line-number]}} "{{search_pattern}}" {{path/to/file}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Search for a pattern in all files recursively in a directory, ignoring binary files:
|
|
|
|
|
|
2025-05-08 12:26:01 -06:00
|
|
|
`egrep {{[-r|--recursive]}} --binary-files={{without-match}} "{{search_pattern}}" {{path/to/directory}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Search for lines that do not match a pattern:
|
|
|
|
|
|
2025-05-08 12:26:01 -06:00
|
|
|
`egrep {{[-v|--invert-match]}} "{{search_pattern}}" {{path/to/file}}`
|