mirror of
https://github.com/tldr-pages/tldr.git
synced 2025-08-16 12:55:44 +02:00
grep: update page (#12901)
Co-authored-by: Vítor Henrique <87824454+vitorhcl@users.noreply.github.com>
This commit is contained in:
parent
50039dc9ce
commit
351d10f241
1 changed files with 6 additions and 6 deletions
|
@ -9,15 +9,15 @@
|
||||||
|
|
||||||
- Search for an exact string (disables regular expressions):
|
- Search for an exact string (disables regular expressions):
|
||||||
|
|
||||||
`grep --fixed-strings "{{exact_string}}" {{path/to/file}}`
|
`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:
|
- Search for a pattern in all files recursively in a directory, showing line numbers of matches, ignoring binary files:
|
||||||
|
|
||||||
`grep --recursive --line-number --binary-files {{without-match}} "{{search_pattern}}" {{path/to/directory}}`
|
`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:
|
- Use extended regular expressions (supports `?`, `+`, `{}`, `()` and `|`), in case-insensitive mode:
|
||||||
|
|
||||||
`grep --extended-regexp --ignore-case "{{search_pattern}}" {{path/to/file}}`
|
`grep {{-E|--extended-regexp}} {{-i|--ignore-case}} "{{search_pattern}}" {{path/to/file}}`
|
||||||
|
|
||||||
- Print 3 lines of context around, before, or after each match:
|
- Print 3 lines of context around, before, or after each match:
|
||||||
|
|
||||||
|
@ -25,12 +25,12 @@
|
||||||
|
|
||||||
- Print file name and line number for each match with color output:
|
- Print file name and line number for each match with color output:
|
||||||
|
|
||||||
`grep --with-filename --line-number --color=always "{{search_pattern}}" {{path/to/file}}`
|
`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:
|
- Search for lines matching a pattern, printing only the matched text:
|
||||||
|
|
||||||
`grep --only-matching "{{search_pattern}}" {{path/to/file}}`
|
`grep {{-o|--only-matching}} "{{search_pattern}}" {{path/to/file}}`
|
||||||
|
|
||||||
- Search `stdin` for lines that do not match a pattern:
|
- Search `stdin` for lines that do not match a pattern:
|
||||||
|
|
||||||
`cat {{path/to/file}} | grep --invert-match "{{search_pattern}}"`
|
`cat {{path/to/file}} | grep {{-v|--invert-match}} "{{search_pattern}}"`
|
||||||
|
|
Loading…
Add table
Reference in a new issue