11 May 2018

ag Cheat Sheet

A hidden gem, replace of grep:

Find exact string (not regexp)
ag -Q "forEach(i -> map.put(i,"

Find files containing "foo", and print the line matches in context:
ag foo

 Find files containing "foo", but only list the filenames:
ag -l foo

 Find files containing "FOO" case-insensitively, and print only the match, rather than the whole line:
ag -i -o FOO

 Find "foo" in files with a name matching "bar":
ag foo -G bar
ag "perfil-usuario" -G java

Find files whose contents match a regular expression:
(double quotes are better, in particular when there is a double or single quote inside of regexp)
ag "^ba(r|z)$"

Find files with a name matching "foo":
ag -g foo

ag hola$

-z --search-zip: Search contents of compressed files. Currently, gz and xz are supported. This option requires that ag is built with lzma and zlib.


http://conqueringthecommandline.com/book/ack_ag

https://www.mankier.com/1/ag


No comments :

Blog Archive

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.