Live data from Hacker News

Use ack instead of grep to parse text files

stevengharms.com

1–10 of 51 posts

Re: Use ack instead of grep to parse text files

#2

  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

Re: Use ack instead of grep to parse text files

#5
post #2

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'…

Maybe it's because you can write the latter also with plain grep:

    grep 'silver.*needle' haystack

Re: Use ack instead of grep to parse text files

#9
post #2

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'…

Also, traditional grep can easily find 'silver needle': `grep silver\ needle haystack`.
Post reply on HN