Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use zgrep and regular expression?

I'm trying to do some research in a .gz file so I found out I should use zcat / zgrep now after a bit of research I can't figure out how to use a regex with zgrep

I tried to do it like this zgrep '[\s\S]{10,}' a.gz but nothing comes out even if there are string of minimum 10 characters in the file.

So how could I use zgrep to display string of minimum 10 characters ?

like image 671
J.erome Avatar asked Sep 19 '25 22:09

J.erome


1 Answers

You should not use \S and \s in a POSIX BRE regex bracket expression as [\S\s] bracket expression matches either \, S or s. Use . instead of [\s\S] to match any char with a POSIX BRE/ERE regex.

Also, in a BRE pattern, {10,} must be written as \{10,\} as otherwise, when unescaped, {10,} matches a literal {10,} string.

Use

zgrep '.\{10,\}' a.gz
like image 191
Wiktor Stribiżew Avatar answered Sep 21 '25 14:09

Wiktor Stribiżew