bzegrep behaviour not consistent with egrep?

David Kirchner dpk at dpk.net
Thu Oct 20 13:11:19 PDT 2005


On 10/20/05, James Long <stable at museum.rain.com> wrote:
> Should these two commands produce identical output?
>
> $ bzegrep "38436|41640" /var/log/maillog.0.bz2 | wc -l
>        0
> $ bzcat /var/log/maillog.0.bz2 | egrep "38436|41640" | wc -l
>      121

Yep. Looks like a bug in the grep code. It looks at the name of the
program to determine what to do. It first checks for 'z' and then 'b'
at the first character, and then increments the pointer. With 'zgrep'
and 'zegrep', that works fine, since it becomes 'grep' and 'egrep'.
With 'bzegrep' it becomes 'zegrep', after it's already looked for 'z'.
It doesn't know what to make of that so it just goes to the default
'grep'.

You can use:

egrep -J "38436|41640" /var/log/maillog.0.bz2

which will filter the file through bzip2.


More information about the freebsd-stable mailing list