The zgrep command is used to search out expressions from a given a file even if it is compressed. All the options that applies to the grep command also applies to the zgrep command.
zgrep [grep options] Expression File name
- -c : This option is used to display the number of matching lines for each file.
zgrep -c "linux" GFG.txt.gz
- -i : This option is used to ignore case sensitivity.
zgrep -i "LINUX" GFG.txt.gz
- -n : This option is used to display the line number of file if the given expression is present in the line.
zgrep -n "linux" GFG.txt.gz
- -v : This option is used to display the lines which doesn’t have the expression present in it. Basically invert the search function.
zgrep -v "linux" GFG.txt.gz
- -e : This option is used to specify the expression but can be used multiple times.
zgrep -e "linux" -e "Linux" GFG.txt.gz
- -o : This option is used to display only the mathced section of the line from the given expression.
zgrep -o "linux" GFG.txt.gz
- -l : This option is used to display the names of the files with the expression present in it.
zgrep -l "linux" *
- -w : By default, zgrep command displays lines even if the expression is found as a sub-string. This option only displays lines only if the whole expression is found.
zgrep -w "linux" GFG.txt.gz
- -h : This option is used to display the matched lines but doesn’t display the file names.
zgrep -h "linux" GFG.txt.gz