I use the following line to replace a string in files:
ag -Q -l "$1" | xargs sed -i '' "s/$1/$2/g"
ag
is the_silver_searcher, of course.
How can I also count the number of files that were affected by this change?
Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up.
Sign up to join this communityI use the following line to replace a string in files:
ag -Q -l "$1" | xargs sed -i '' "s/$1/$2/g"
ag
is the_silver_searcher, of course.
How can I also count the number of files that were affected by this change?
You could use tee
in the pipe line and create a temporary file, then run wc -l
to count the number of files (lines).
ag -Q -l "$1" | tee -a /tmp/num | xargs sed -i '' "s/$1/$2/g"; wc -l /tmp/num; rm /tmp/num