LinuxCommandLibrary

zfgrep

TLDR

Search for literal string in gzipped file

$ zfgrep "[string]" [file.gz]
copy
Case-insensitive search
$ zfgrep -i "[string]" [file.gz]
copy
Show line numbers
$ zfgrep -n "[string]" [file.gz]
copy
Count matching lines
$ zfgrep -c "[string]" [file.gz]
copy
List files containing matches
$ zfgrep -l "[string]" [*.gz]
copy

SYNOPSIS

zfgrep [grep-options] [-e] pattern [file...]

DESCRIPTION

zfgrep searches for fixed strings in gzip-compressed files without manual decompression. It's equivalent to zcat file.gz | fgrep pattern but more convenient.
The "f" indicates fixed string matching (like grep -F). Patterns are interpreted literally, not as regular expressions. This is faster than regex matching and useful when searching for strings containing special characters.
zfgrep automatically handles both compressed and uncompressed files, making it safe for mixed file sets.
Multiple patterns can be specified, one per line, using -e or by newline-separating them.

PARAMETERS

-i

Case-insensitive matching
-n
Show line numbers
-l
List filenames with matches only
-c
Count matching lines
-v
Invert match (show non-matching lines)
-h
Suppress filename in output
-e pattern
Specify pattern
-x
Match whole lines only

CAVEATS

Only gzip compression is supported. Use bzfgrep for bzip2 files or pipe through appropriate decompressors for other formats.
Fixed string matching means special characters like .,\*, [ are literal. Use zgrep or zegrep if regex is needed.
Processing large compressed files requires CPU for decompression.

SEE ALSO

zgrep(1), zegrep(1), fgrep(1), zcat(1), gzip(1)

Copied to clipboard