3 ms·
ack '(?=silver).*needle' haystack is really not the same as: grep needle haystack|grep silver Because with the double grep method, a match will be made whe
by gnosis 14y ago
ack '(?=silver).*needle' haystack
is really not the same as:
grep needle haystack|grep silver
Because with the double grep method, a match will be made whether "silver" is before or after "needle"; while with the single ack command shown above, a match will only be made when "silver" comes before "needle".
Also, I'm not sure why the author uses
ack '(?=silver).*needle' haystack
instead of simply:
ack 'silver.*needle' haystack
- nene 14y agoMaybe it's because you can write the latter also with plain grep: grep 'silver.*needle' haystack
- Firehed 14y agoThat assumes that "silver" will appear before "needle", which may not always be the case. `grep needle file | grep silver` gets you lines containing both "silver" and "needle" but not necessarily in that order.
- loeg 14y agoAlso, traditional grep can easily find 'silver needle': `grep silver\ needle haystack`.
- philh 14y agoack hilights results by default, so `(?=silver.*)needle` would potentially be useful. But, yes, not the same as the grep|grep.