4 ms·
cp /usr/bin/grep ack Find the needles ./ack needle haystack Find the silver needles ./ack silver.*needle Find all needles except lead ones ./ack
by lispertoascheme 14y ago
cp /usr/bin/grep ack
Find the needles
./ack needle haystack
Find the silver needles
./ack silver.*needle
Find all needles except lead ones
./ack '[^^][^e.][^a.][^d.] needle' haystack
That last one could be tricky if there's other types of needles with names like "ead needle" or "mead needle". But using the haystack he gives us BRE can do the job, easily.
Perl regex may be easy to use but they are inferior from a performance perspective. As someone else said, they're slower than BRE or ERE. Moreover, even if speed is not an issue, you pay a price in the amount of memory you will need compared with line-based utilities like, e.g., sed and awk.
Find the needles
sed '/needle/!d;/needle/q' haystack
Find the silver needles
sed '/silver needle/!d;/silver needle/q' haystack
Find all needles except lead ones
sed '/lead needle/d;/needle/!d/needle/q' haystack
My preference is to use (f)lex if I want a fast "parser" (scanner). Its regex is more than adequate.