by danso · 10y ago · 0 comments
--output=expr
Output the evaluation of expr for each line (turns off text
highlighting) If PATTERN matches more than once then a line is
output for each non-overlapping match. For more information please
see the section "Examples of --output".
Basically, it allows you to use captured groups in the output: cat file | ag '(\w+) (\d+)' --output '$1 is $2 years old'
On the other hand, ag allows multiline matching. So I end up using ag and ack together frequently. sed -rn 's/([a-zA-Z]+) ([0-9]+)/\1 is \2 years old/p' file cat file | perl -ne 'print if s/(\w+) (\d+)/\1 is \2 years old/'
My only point is sometimes old school standard tools are plenty.1: https://www.gnu.org/software/sed/manual/sed.html#Extended-re...