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