Is it worth learning grep or ack or a similar tool? When I need to do these sort of tasks, I do them in a scripting language with some combination of split() and regex instead of using command line tools. But, I'm just doing that because it's what I know. Would I end up saving a significant amount of time if I learned to use grep instead?
Use ack instead of grep to parse text files
31–40 of 51 posts
Re: Use ack instead of grep to parse text files
#32Is it worth learning grep or ack or a similar tool? When I need to do these sort of tasks, I do them in a scripting language with some combination of split() and regex instead of using command line tools. But, I'm just doing that because it's what I know. Would I end up saving a significant amount of time if I learned to use grep instead?
I'd say start with ack for its ease of use, but knowing grep is important. I prefer ack but most of the boxes i work on don't have ack installed (and won't).
Re: Use ack instead of grep to parse text files
#33ack '(?=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'…
Re: Use ack instead of grep to parse text files
#34Why is: ack -C5 'scope(?!.*lambda)' app/models Better than: grep -C5 scope app/models | grep -v lambda ?
Re: Use ack instead of grep to parse text files
#35Saying "You should stop using them. Now." is ridiculous. Why do I need to stop anything if it does what I need?
Re: Use ack instead of grep to parse text files
#36[shameless plug] Try also the pure-Python based alternative to ack called "pss" (pip/easy_install or https://bitbucket.org/eliben/pss).
Re: Use ack instead of grep to parse text files
#37Re: Use ack instead of grep to parse text files
#38Why is: ack -C5 'scope(?!.*lambda)' app/models Better than: grep -C5 scope app/models | grep -v lambda ?
The first one gets you five lines around all of the scopes without lambdas. The second one gets you five lines around all the scopes (including those with lambdas) and then omits all of the lines with lambdas, some of which will have caused a match in the first grep, and some of which may be part of the context of matches in the first grep. You will get both contexts with no match in the middle and matches with incom…
Re: Use ack instead of grep to parse text files
#39Re: Use ack instead of grep to parse text files
#40ack '(?=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