1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-04-29 23:24:55 +02:00
tldr/pages/common/grep.md
Reinhart Previano Koentjoro 1a7645ceb2
egrep, grep: use serial comma, add Indonesian translations (#15494)
* egrep, grep: use serial comma, add Indonesian translations

* grep: reverse Spanish fixes

* grep: revert fixes for Romance languages (Dutch, French, Portuguese)

* grep: revert fixes for Romance languages (German)
2025-01-14 22:56:32 +01:00

36 lines
1.4 KiB
Markdown

# grep
> Find patterns in files using regular expressions.
> More information: <https://www.gnu.org/software/grep/manual/grep.html>.
- Search for a pattern within a file:
`grep "{{search_pattern}}" {{path/to/file}}`
- Search for an exact string (disables regular expressions):
`grep {{-F|--fixed-strings}} "{{exact_string}}" {{path/to/file}}`
- Search for a pattern in all files recursively in a directory, showing line numbers of matches, ignoring binary files:
`grep {{-r|--recursive}} {{-n|--line-number}} --binary-files {{without-match}} "{{search_pattern}}" {{path/to/directory}}`
- Use extended regular expressions (supports `?`, `+`, `{}`, `()`, and `|`), in case-insensitive mode:
`grep {{-E|--extended-regexp}} {{-i|--ignore-case}} "{{search_pattern}}" {{path/to/file}}`
- Print 3 lines of context around, before, or after each match:
`grep --{{context|before-context|after-context}} 3 "{{search_pattern}}" {{path/to/file}}`
- Print file name and line number for each match with color output:
`grep {{-H|--with-filename}} {{-n|--line-number}} --color=always "{{search_pattern}}" {{path/to/file}}`
- Search for lines matching a pattern, printing only the matched text:
`grep {{-o|--only-matching}} "{{search_pattern}}" {{path/to/file}}`
- Search `stdin` for lines that do not match a pattern:
`cat {{path/to/file}} | grep {{-v|--invert-match}} "{{search_pattern}}"`