LinuxCommandLibrary

bzegrep

Search compressed files for a pattern

TLDR

Search for extended regular expressions (supporting ?, +, {}, () and |) in a compressed file (case-sensitive)

$ bzegrep "[search_pattern]" [path/to/file]
copy

Search for extended regular expressions (supporting ?, +, {}, () and |) in a compressed file (case-insensitive)
$ bzegrep --ignore-case "[search_pattern]" [path/to/file]
copy

Search for lines that do not match a pattern
$ bzegrep --invert-match "[search_pattern]" [path/to/file]
copy

Print file name and line number for each match
$ bzegrep --with-filename --line-number "[search_pattern]" [path/to/file]
copy

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

Recursively search files in a bzip2 compressed tar archive for a pattern
$ bzegrep --recursive "[search_pattern]" [path/to/file]
copy

SYNOPSIS

bzegrep [grep_options] pattern [file1 file2 ...]

PARAMETERS

grep_options
    Options that can be passed to the underlying grep command. These can include options for case-insensitive search (-i), displaying line numbers (-n), inverting the search (-v), and more. Consult the grep manual page for a comprehensive list.

pattern
    The regular expression pattern to search for within the bzip2-compressed files.

file1 file2 ...
    One or more bzip2-compressed files (.bz2 extension) to search within. If no files are specified, bzegrep will read from standard input, if the input is compressed with bzip2.

DESCRIPTION

bzegrep is a command-line utility in Linux systems used to search for patterns within bzip2-compressed files. It's essentially a wrapper around bzcat and grep, allowing you to search through compressed data without needing to decompress it manually. bzegrep will uncompress and search the files specified in the file parameters and the output is equivalent to running grep on the uncompressed files.
This is particularly useful when dealing with large log files or other data stored in a compressed format to save disk space. Using bzegrep provides a more efficient workflow by eliminating the need for manual decompression and re-compression after searching.
When bzegrep find a line that matches the required pattern, the file name will be printed with the matching pattern in that line. It supports most of the commonly used grep options, enabling flexible and powerful searches.

EXIT STATUS

The exit status is 0 if selected lines are found, and 1 if not found. If an error occurred the exit status is 2.
The exit code is the same as the grep command.

USAGE NOTES

If no files are specified on the command line, bzegrep reads from the standard input. Note that due to limitations in the bzip2 file format, bzegrep might not always work correctly on concatenated bzip2 files. If you need to process such files, consider decompressing them first using bzcat.

SEE ALSO

bzcat(1), grep(1), bzip2(1), bzless(1), bzmore(1)

Copied to clipboard