2023-04-02 03:28:28 +05:45
|
|
|
# xzgrep
|
|
|
|
|
2023-07-16 08:00:03 +02:00
|
|
|
> Search files possibly compressed with `xz`, `lzma`, `gzip`, `bzip2`, `lzop`, or `zstd` using regular expressions.
|
2023-04-02 03:28:28 +05:45
|
|
|
> See also: `grep`.
|
2023-07-16 08:00:03 +02:00
|
|
|
> More information: <https://manned.org/xzgrep>.
|
2023-04-02 03:28:28 +05:45
|
|
|
|
|
|
|
- Search for a pattern within a file:
|
|
|
|
|
2023-07-16 08:00:03 +02:00
|
|
|
`xzgrep "{{search_pattern}}" {{path/to/file}}`
|
2023-04-02 03:28:28 +05:45
|
|
|
|
|
|
|
- Search for an exact string (disables regular expressions):
|
|
|
|
|
2025-05-11 20:03:52 +03:00
|
|
|
`xzgrep {{[-F|--fixed-strings]}} "{{exact_string}}" {{path/to/file}}`
|
2023-04-02 03:28:28 +05:45
|
|
|
|
|
|
|
- Search for a pattern in all files showing line numbers of matches:
|
|
|
|
|
2025-05-11 20:03:52 +03:00
|
|
|
`xzgrep {{[-n|--line-number]}} "{{search_pattern}}" {{path/to/file}}`
|
2023-04-02 03:28:28 +05:45
|
|
|
|
|
|
|
- Use extended regular expressions (supports `?`, `+`, `{}`, `()` and `|`), in case-insensitive mode:
|
|
|
|
|
2025-05-11 20:03:52 +03:00
|
|
|
`xzgrep {{[-E|--extended-regexp]}} {{[-i|--ignore-case]}} "{{search_pattern}}" {{path/to/file}}`
|
2023-04-02 03:28:28 +05:45
|
|
|
|
2025-05-11 20:03:52 +03:00
|
|
|
- Print 3 lines of [C]ontext around, [B]efore, or [A]fter each match:
|
2023-04-02 03:28:28 +05:45
|
|
|
|
2025-05-11 20:03:52 +03:00
|
|
|
`xzgrep --{{context|before-context|after-context}} {{3}} "{{search_pattern}}" {{path/to/file}}`
|
2023-04-02 03:28:28 +05:45
|
|
|
|
|
|
|
- Print file name and line number for each match with color output:
|
|
|
|
|
2025-05-11 20:03:52 +03:00
|
|
|
`xzgrep {{[-H|--with-filename]}} {{[-n|--line-number]}} --color=always "{{search_pattern}}" {{path/to/file}}`
|
2023-04-02 03:28:28 +05:45
|
|
|
|
|
|
|
- Search for lines matching a pattern, printing only the matched text:
|
|
|
|
|
2025-05-11 20:03:52 +03:00
|
|
|
`xzgrep {{[-o|--only-matching]}} "{{search_pattern}}" {{path/to/file}}`
|