Re:Ack is a grep-like tool, optimised for programmers
by sillysaurus3 on Wednesday May 07, 2014 @10:29AM
(#7710299)
Examples, please? If you have the time.
[ Parent
| on HN ]
Re:Ack is a grep-like tool, optimised for programmers
by base698 on Wednesday May 07, 2014 @11:40AM
(#7710768)
These are just a few examples I do pretty frequently:
Nested Search:
ag functionName | ag moreSpecificContextLikeArgs
Find variable changed yesterday: git log -p --since yesterday | ag varName
Find controllers changed yesterday: git log --oneline --showfile | ag controllers
What files did I work on last week: git log --name-only --oneline --author me --since 1.weeks
How many JS commits did I do last month? git log --since 1.months --author me --name-only | ag -i '\.js$' | wc -l
How many JS commits did I do on each file last month? git log --since 1.months --author me --name-only | ag -i '\.js$' | awk '{arr[$1]++} END {for(i in arr) print arr[i]," - ",i}' | sort -r -n
Change a "classname" from MyClass to BetterName: ag MyClass # verify it only finds what you think it will
ag MyClass | awk -F':' '{print $1}' | sort | uniq | while read line
do
sed -i' ' 's/MyClass/BetterName/g' $line
done
Re:Ack is a grep-like tool, optimised for programmers
by a_e_k on Wednesday May 07, 2014 @12:53PM
(#7711259)
Nested searches are handy. They can also be used to find cases of one thing within a few lines of proximity to another:
ack -C5 firstThing | less
/secondThing
One bonus ack trick that I like also like is bulk loading into Emacs for further manipulation (e.g., multi-occur and then occur-edit-mode): emacsclient -n `ack -l functionName`