I need to replace something in a number of files using regex. I do it like this:
#!/usr/bin/env bash
find /path/to/dir \
-type f \
-name '*.txt' \
-exec perl -e 's/replaceWhat/replaceWith/ig' -pi '{}' \; \
-print \
| awk '{count = count+1 }; END { print count " file(s) handled" }'
echo "Done!"
This code shows user the count of files it dealed with. But how could I count not files, but replaces? Every file handled could produce zero, one or many replaces with regex.
(??{ code })
syntax to increment the counter in the replacement. see perldoc.perl.org/perlre.html