Why is 'grep -i' so slow? How to do it faster for ASCII?

Posted by Vi. on Super User See other posts from Super User or by Vi.
Published on 2011-09-06T12:55:03Z Indexed on 2012/04/06 23:34 UTC
Read the original article Hit count: 217

Filed under:
|

Consider:

$ time lzop -d < tvtropes-index.lzo | egrep -B 5 '[Dd][eE][sS][cC][eE][nN][dD] ?[Ff][rR][oO][mM]'
real    0m0.438s

$ time lzop -d < tvtropes-index.lzo | egrep -B 5 'descend ?from' -i
real    0m11.294s

Both search case insensitively. Why is the -i version so slow? How do I make grep -i fast without entering things like [iI][nN] [tT][hH][iI][sS] [wW][aA][Yy]?

For example,

perl -ne 'print if /descend ?from/i'

works fast, but '-B 5' is not as trivial to implement as in grep (as well as other options).

© Super User or respective owner

Related posts about linux

Related posts about grep