Linux command
zegrep 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Search for pattern in gzipped file
zegrep "[pattern]" [file.gz]
Case-insensitive search
zegrep -i "[pattern]" [file.gz]
Show line numbers
zegrep -n "[pattern]" [file.gz]
Search multiple files
zegrep "[pattern]" [file1.gz] [file2.gz]
Extended regex search (alternation, quantifiers)
zegrep "(foo|bar)+" [file.gz]
说明
zegrep searches for patterns in gzip-compressed files without manually decompressing them. It's equivalent to zcat file.gz | egrep pattern but more convenient. The "e" indicates extended regular expression support, same as grep -E. This allows patterns with +, ?, |, and () without escaping. zegrep automatically detects whether input files are compressed. Uncompressed files are searched normally, making it safe to use on mixed file sets. Multiple patterns can be specified with -e or by separating with | in the pattern.
参数
- -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 (useful for patterns starting with -)
FAQ
What is the zegrep command used for?
zegrep searches for patterns in gzip-compressed files without manually decompressing them. It's equivalent to zcat file.gz | egrep pattern but more convenient. The "e" indicates extended regular expression support, same as grep -E. This allows patterns with +, ?, |, and () without escaping. zegrep automatically detects whether input files are compressed. Uncompressed files are searched normally, making it safe to use on mixed file sets. Multiple patterns can be specified with -e or by separating with | in the pattern.
How do I run a basic zegrep example?
Run `zegrep "[pattern]" [file.gz]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -i do in zegrep?
Case-insensitive matching