LinuxCommandLibrary

xzgrep

search compressed files for a regular expression

TLDR

Search for a pattern within a file

$ xzgrep "[search_pattern]" [path/to/compressed/file]
copy


Search for an exact string (disables regular expressions)
$ xzgrep --fixed-strings "[exact_string]" [path/to/compressed/file]
copy


Search for a pattern in all files showing line numbers of matches
$ xzgrep --line-number "[search_pattern]" [path/to/compressed/file]
copy


Use extended regular expressions (supports ?, +, {}, () and |), in case-insensitive mode
$ xzgrep --extended-regexp --ignore-case "[search_pattern]" [path/to/file]
copy


Print 3 lines of context around, before, or after each match
$ xzgrep --[context|before-context|after-context]=[3] "[search_pattern]" [path/to/file]
copy


Print file name and line number for each match with color output
$ xzgrep --with-filename --line-number --color=always "[search_pattern]" [path/to/file]
copy


Search for lines matching a pattern, printing only the matched text
$ xzgrep --only-matching "[search_pattern]" [path/to/file]
copy

SYNOPSIS

xzgrep [grep_options] [-e] pattern file...
xzegrep ...
xzfgrep ...
lzgrep ...
lzegrep ...
lzfgrep ...

DESCRIPTION

xzgrep invokes grep(1) on files which may be either uncompressed or compressed with xz(1), lzma(1), gzip(1), bzip2(1), or lzop(1). All options specified are passed directly to grep(1).

If no file is specified, then standard input is decompressed if necessary and fed to grep(1). When reading from standard input, gzip(1), bzip2(1), and lzop(1) compressed files are not supported.

If xzgrep is invoked as xzegrep or xzfgrep then egrep(1) or fgrep(1) is used instead of grep(1). The same applies to names lzgrep, lzegrep, and lzfgrep, which are provided for backward compatibility with LZMA Utils.

ENVIRONMENT

GREP

If the GREP environment variable is set, xzgrep uses it instead of grep(1), egrep(1), or fgrep(1).

SEE ALSO

grep(1), xz(1), gzip(1), bzip2(1), lzop(1), zgrep(1)

Copied to clipboard