LinuxCommandLibrary

bzfgrep

Search bzip2-compressed files for patterns

TLDR

Search for lines matching the list of search strings separated by new lines in a compressed file (case-sensitive)

$ bzfgrep "[search_string]" [path/to/file]
copy

Search for lines matching the list of search strings separated by new lines in a compressed file (case-insensitive)
$ bzfgrep [[-i|--ignore-case]] "[search_string]" [path/to/file]
copy

Search for lines that do not match the list of search strings separated by new lines in a compressed file
$ bzfgrep [[-v|--invert-match]] "[search_string]" [path/to/file]
copy

Print file name and line number for each match
$ bzfgrep [[-H|--with-filename]] [[-n|--line-number]] "[search_string]" [path/to/file]
copy

Search for lines matching a pattern, printing only the matched text
$ bzfgrep [[-o|--only-matching]] "[search_string]" [path/to/file]
copy

Recursively search files in a bzip2 compressed tar archive for the given list of strings
$ bzfgrep [[-r|--recursive]] "[search_string]" [path/to/file]
copy

SYNOPSIS

bzfgrep [grep_options] pattern [file1] [file2] ...

PARAMETERS

-E
    Interpret pattern as an extended regular expression (egrep).

-F
    Interpret pattern as a fixed string (fgrep).

-i
    Ignore case distinctions in pattern and input files.

-v
    Select non-matching lines.

-w
    Select only whole words matching pattern.

-x
    Select only whole line matching pattern.

-c
    Print only a count of matching lines per file.

-l
    Print only the names of files containing matching lines.

-n
    Precede each matching line with its line number.

-h
    Suppress the prefixing of filenames on output.

-s
    Suppress error messages about nonexistent or unreadable files.

-o
    Print only the matching parts of a line.

pattern
    The search pattern (string or regular expression).

[file1] [file2] ...
    One or more bzip2-compressed files to search. If no files are specified, standard input is searched.

DESCRIPTION

bzfgrep is a command-line utility in Linux and Unix-like operating systems used to search for patterns in bzip2-compressed files. It is essentially a wrapper around bzip2 -dc (which decompresses the file to standard output) piped to grep. This allows users to search for specific strings or regular expressions within the compressed content without needing to decompress the entire file first. This significantly improves efficiency, especially when dealing with large archives.
The command supports most of the standard grep options, making it a versatile tool for log analysis, data mining, and other tasks where searching through compressed text data is necessary. It automatically handles the decompression process, simplifying the workflow for users. The exit status of bzfgrep is the same as that of grep.

CAVEATS

bzfgrep relies on bzip2 and grep being installed on the system. Its performance depends on the size and complexity of the compressed files and the search pattern. Very large files may take a significant amount of time to search. Note: bzfgrep is typically a shell script, so precise behavior might vary depending on system configuration.

EXIT STATUS

The exit status of bzfgrep is 0 if matches were found, 1 if no matches were found, and 2 if an error occurred.

ENVIRONMENT VARIABLES

bzfgrep respects environment variables such as GREP_OPTIONS, which can be used to specify default options for grep. It also uses the PATH environment variable to find the grep command. If `GREP_OPTIONS` is set, any explicit options given to `bzfgrep` in the command-line will override it.

SEE ALSO

grep(1), bzip2(1), bzcat(1), zgrep(1), xzgrep(1)

Copied to clipboard