From 4d0dbeac8baf7c2b09de0d8e11a091f0ca36f002 Mon Sep 17 00:00:00 2001 From: Managor <42655600+Managor@users.noreply.github.com> Date: Tue, 23 Dec 2025 06:57:14 +0200 Subject: [PATCH] grep, bzgrep, codespell, rg, xzgrep, zgrep: simplify, clarify and reorder examples (#20203) Co-authored-by: Ivan Baluta --- pages/common/bzgrep.md | 14 +++++++------- pages/common/codespell.md | 2 +- pages/common/grep.md | 16 ++++++++-------- pages/common/rg.md | 8 ++++---- pages/common/xzgrep.md | 10 +++++----- pages/common/zgrep.md | 10 +++++----- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/pages/common/bzgrep.md b/pages/common/bzgrep.md index 2c2ae7981c..22ebd0ffa1 100644 --- a/pages/common/bzgrep.md +++ b/pages/common/bzgrep.md @@ -7,13 +7,13 @@ `bzgrep "{{search_pattern}}" {{path/to/file}}` -- Use extended `regex` (supports `?`, `+`, `{}`, `()`, and `|`), in case-insensitive mode: +- Recursively search files in a bzip2 compressed `.tar` archive for a pattern: -`bzgrep {{[-E|--extended-regexp]}} {{[-i|--ignore-case]}} "{{search_pattern}}" {{path/to/file}}` +`bzgrep {{[-r|--recursive]}} "{{search_pattern}}" {{path/to/tar_file}}` - Print 3 lines of [C]ontext around, [B]efore, or [A]fter each match: -`bzgrep --{{context|before-context|after-context}} {{3}} "{{search_pattern}}" {{path/to/file}}` +`bzgrep {{--context|--before-context|--after-context}} 3 "{{search_pattern}}" {{path/to/file}}` - Print file name and line number for each match: @@ -23,10 +23,10 @@ `bzgrep {{[-o|--only-matching]}} "{{search_pattern}}" {{path/to/file}}` -- Recursively search files in a bzip2 compressed `.tar` archive for a pattern: - -`bzgrep {{[-r|--recursive]}} "{{search_pattern}}" {{path/to/tar_file}}` - - Search `stdin` for lines that do not match a pattern: `cat {{path/to/bz_compressed_file}} | bzgrep {{[-v|--invert-match]}} "{{search_pattern}}"` + +- Use extended `regex` (supports `?`, `+`, `{}`, `()`, and `|`), in case-insensitive mode: + +`bzgrep {{[-E|--extended-regexp]}} {{[-i|--ignore-case]}} "{{search_pattern}}" {{path/to/file}}` diff --git a/pages/common/codespell.md b/pages/common/codespell.md index 572382ea42..21da2f8910 100644 --- a/pages/common/codespell.md +++ b/pages/common/codespell.md @@ -29,7 +29,7 @@ - Print 3 lines of [C]ontext around, [B]efore, or [A]fter each match: -`codespell --{{context|before-context|after-context}} 3` +`codespell {{--context|--before-context|--after-context}} 3` - Check file names for typos, in addition to file contents: diff --git a/pages/common/grep.md b/pages/common/grep.md index f20a5e08fd..8b2a91d58e 100644 --- a/pages/common/grep.md +++ b/pages/common/grep.md @@ -4,7 +4,7 @@ > See also: `regex`. > More information: . -- Search for a pattern within a file: +- Search for a pattern within files: `grep "{{search_pattern}}" {{path/to/file1 path/to/file2 ...}}` @@ -12,13 +12,9 @@ `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, ignoring binary files: -`grep {{[-rnI|--recursive --line-number --binary-files=without-match]}} "{{search_pattern}}" {{path/to/directory}}` - -- Use extended `regex`es (supports `?`, `+`, `{}`, `()`, and `|`), in case-insensitive mode: - -`grep {{[-Ei|--extended-regexp --ignore-case]}} "{{search_pattern}}" {{path/to/file}}` +`grep {{[-rI|--recursive --binary-files=without-match]}} "{{search_pattern}}" {{path/to/directory}}` - Print 3 lines of [C]ontext around, [B]efore, or [A]fter each match: @@ -28,10 +24,14 @@ `grep {{[-Hn|--with-filename --line-number]}} --color=always "{{search_pattern}}" {{path/to/file}}` -- Search for lines matching a pattern, printing only the matched text: +- Print only the matched text: `grep {{[-o|--only-matching]}} "{{search_pattern}}" {{path/to/file}}` - Read data from `stdin` and do not print lines that match a pattern: `cat {{path/to/file}} | grep {{[-v|--invert-match]}} "{{search_pattern}}"` + +- Use extended `regex`es (supports `?`, `+`, `{}`, `()`, and `|`), in case-insensitive mode: + +`grep {{[-Ei|--extended-regexp --ignore-case]}} "{{search_pattern}}" {{path/to/file}}` diff --git a/pages/common/rg.md b/pages/common/rg.md index 99ae5ccce1..9af754e813 100644 --- a/pages/common/rg.md +++ b/pages/common/rg.md @@ -12,6 +12,10 @@ `rg {{pattern}} {{path/to/file_or_directory}}` +- Search for a literal string pattern: + +`rg {{[-F|--fixed-strings]}} -- {{string}}` + - Include hidden files and entries listed in `.gitignore`: `rg {{[-.|--hidden]}} --no-ignore {{pattern}}` @@ -31,7 +35,3 @@ - Show lines that do not match the pattern: `rg {{[-v|--invert-match]}} {{pattern}}` - -- Search for a literal string pattern: - -`rg {{[-F|--fixed-strings]}} -- {{string}}` diff --git a/pages/common/xzgrep.md b/pages/common/xzgrep.md index 3111075053..baae587b2d 100644 --- a/pages/common/xzgrep.md +++ b/pages/common/xzgrep.md @@ -16,13 +16,9 @@ `xzgrep {{[-n|--line-number]}} "{{search_pattern}}" {{path/to/file}}` -- Use extended `regex` (supports `?`, `+`, `{}`, `()`, and `|`), in case-insensitive mode: - -`xzgrep {{[-E|--extended-regexp]}} {{[-i|--ignore-case]}} "{{search_pattern}}" {{path/to/file}}` - - Print 3 lines of [C]ontext around, [B]efore, or [A]fter each match: -`xzgrep --{{context|before-context|after-context}} {{3}} "{{search_pattern}}" {{path/to/file}}` +`xzgrep {{--context|--before-context|--after-context}} 3 "{{search_pattern}}" {{path/to/file}}` - Print file name and line number for each match with color output: @@ -31,3 +27,7 @@ - Search for lines matching a pattern, printing only the matched text: `xzgrep {{[-o|--only-matching]}} "{{search_pattern}}" {{path/to/file}}` + +- Use extended `regex` (supports `?`, `+`, `{}`, `()`, and `|`), in case-insensitive mode: + +`xzgrep {{[-E|--extended-regexp]}} {{[-i|--ignore-case]}} "{{search_pattern}}" {{path/to/file}}` diff --git a/pages/common/zgrep.md b/pages/common/zgrep.md index 38cd030d07..0ad82c00c1 100644 --- a/pages/common/zgrep.md +++ b/pages/common/zgrep.md @@ -7,6 +7,10 @@ `zgrep {{pattern}} {{path/to/compressed_file}}` +- Print 3 lines of [C]ontext around, [B]efore, or [A]fter each match: + +`zgrep {{--context|--before-context|--after-context}} 3 {{pattern}} {{path/to/compressed_file}}` + - Grep a pattern in a compressed file (case-insensitive): `zgrep {{[-i|--ignore-case]}} {{pattern}} {{path/to/compressed_file}}` @@ -23,10 +27,6 @@ `zgrep {{[-e|--regexp]}} "{{pattern_1}}" {{[-e|--regexp]}} "{{pattern_2}}" {{path/to/compressed_file}}` -- Use extended `regex` (supporting `?`, `+`, `{}`, `()`, and `|`): +- Use extended `regex` (supports `?`, `+`, `{}`, `()`, and `|`): `zgrep {{[-E|--extended-regexp]}} {{regex}} {{path/to/file}}` - -- Print 3 lines of [C]ontext around, [B]efore, or [A]fter each match: - -`zgrep --{{context|before-context|after-context}} 3 {{pattern}} {{path/to/compressed_file}}`