2025-03-14 21:59:59 -06:00
|
|
|
|
# zgrep
|
|
|
|
|
|
|
|
|
|
|
|
> Grep text patterns from files within compressed file (equivalent to `grep -Z`).
|
|
|
|
|
|
> More information: <https://manned.org/zgrep>.
|
|
|
|
|
|
|
|
|
|
|
|
- Grep a pattern in a compressed file (case-sensitive):
|
|
|
|
|
|
|
|
|
|
|
|
`zgrep {{pattern}} {{path/to/compressed/file}}`
|
|
|
|
|
|
|
|
|
|
|
|
- Grep a pattern in a compressed file (case-insensitive):
|
|
|
|
|
|
|
2025-04-25 19:33:51 -06:00
|
|
|
|
`zgrep {{[-i|--ignore-case]}} {{pattern}} {{path/to/compressed/file}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
|
|
- Output count of lines containing matched pattern in a compressed file:
|
|
|
|
|
|
|
2025-04-25 19:33:51 -06:00
|
|
|
|
`zgrep {{[-c|--count]}} {{pattern}} {{path/to/compressed/file}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
|
|
- Display the lines which don’t have the pattern present (Invert the search function):
|
|
|
|
|
|
|
2025-04-25 19:33:51 -06:00
|
|
|
|
`zgrep {{[-v|--invert-match]}} {{pattern}} {{path/to/compressed/file}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
|
|
- Grep a compressed file for multiple patterns:
|
|
|
|
|
|
|
2025-04-25 19:33:51 -06:00
|
|
|
|
`zgrep {{[-e|--regexp]}} "{{pattern_1}}" {{[-e|--regexp]}} "{{pattern_2}}" {{path/to/compressed/file}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
|
|
- Use extended regular expressions (supporting `?`, `+`, `{}`, `()` and `|`):
|
|
|
|
|
|
|
2025-04-25 19:33:51 -06:00
|
|
|
|
`zgrep {{[-E|--extended-regexp]}} {{regular_expression}} {{path/to/file}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
|
|
- Print 3 lines of [C]ontext around, [B]efore, or [A]fter each match:
|
|
|
|
|
|
|
2025-05-08 12:26:01 -06:00
|
|
|
|
`zgrep --{{context|before-context|after-context}} 3 {{pattern}} {{path/to/compressed/file}}`
|