While I agree that in theory
grep should be faster than
awk, in practice, YMMV as that depends a lot on the implementation you use.
here comparing busybox 1.20.0's grep and awk, GNU grep 2.14, mawk 1.3.3, GNU awk 4.0.1 on Debian/Linux 7.0 amd64 (with glibc 2.17) in a UTF-8 locale on a 240MB file of 2.5M lines of ASCII-only characters.
$ time busybox grep error error | wc -l
busybox grep error error 8.31s user 0.12s system 99% cpu 8.450 total
wc -l 0.07s user 0.11s system 2% cpu 8.448 total
$ time busybox awk /error/ error | wc -l
busybox awk /error/ error 2.39s user 0.84s system 98% cpu 3.265 total
wc -l 0.12s user 1.23s system 41% cpu 3.264 total
$ time grep error error | wc -l
grep error error 0.80s user 0.10s system 99% cpu 0.914 total
wc -l 0.00s user 0.11s system 12% cpu 0.913 total
$ time mawk /error/ error | wc -l
mawk /error/ error 0.54s user 0.13s system 91% cpu 0.732 total
wc -l 0.03s user 0.08s system 14% cpu 0.731 total
$ time gawk /error/ error | wc -l
gawk /error/ error 1.37s user 0.12s system 99% cpu 1.494 total
wc -l 0.04s user 0.07s system 7% cpu 1.492 total
In the C locale, only GNU grep gets a significant boost and becomes faster than
The dataset, the type of the regexp may also make a big difference. For regexps,
awk should be compared to
grep -E as
awk's regexps are extended REs.
For this dataset,
awk could be faster than
grep on busybox based systems or systems where
mawk is the default
awk and the default locale is UTF-8 based (IIRC, it used to be the case in Ubuntu).