Live data from Hacker News

Skip grep, use awk

blog.jpalardy.com

1–10 of 136 posts

Re: Skip grep, use awk

#6
While awk is indeed under-appreciated, there are many instances where using grep to pre-filter your input is helpful because the grep family (GNU grep, agrep, etc.) can match strings much much faster than awk's regex engine.

For example: GNU grep uses a heavily optimized implementation of the Boyer-Moore string search algorithm [1] which (it is claimed) requires just 3 (x86) cycles per byte of input. Boyer-Moore only searches for literal strings, but grep will extract the longest literal from the search regex (e.g. the string "foo" from the regex /foo(bar|baz)+/) and use Boyer-Moore to find candidate matches that are then verified using the regex engine.

So if you have a large corpus of text to search, grep is your friend. It can easily saturate your I/O bandwidth and perform an order of magnitude faster than typical "big data" platforms. [2]

[1] https://lists.freebsd.org/pipermail/freebsd-current/2010-Aug...

[2] https://aadrake.com/command-line-tools-can-be-235x-faster-th...

Re: Skip grep, use awk

#8
post #6

While awk is indeed under-appreciated, there are many instances where using grep to pre-filter your input is helpful because the grep family (GNU grep, agrep, etc.) can match strings much much faster than awk's regex engine. For example: GNU grep uses a heavily optimized implementation of the Boyer-Moore string search algorithm [1] which (it is claimed) requires just 3 (x86) cycles per byte of input. Boyer-Moore only…

I have found ack and ag to be much faster than grep (I should actually time this).

Re: Skip grep, use awk

#9
post #6

While awk is indeed under-appreciated, there are many instances where using grep to pre-filter your input is helpful because the grep family (GNU grep, agrep, etc.) can match strings much much faster than awk's regex engine. For example: GNU grep uses a heavily optimized implementation of the Boyer-Moore string search algorithm [1] which (it is claimed) requires just 3 (x86) cycles per byte of input. Boyer-Moore only…

I have found ack and ag to be much faster than grep (I should actually time this).

They are perceived as faster because they automatically skip binary and VCS-ignored files. grep is faster.
Post reply on HN