Inferno sh command to find files in a git repo with oldtext and update them
apply {sed 's,oldtext,newtext,g;s,related old text,related new text,g' $1 > $1.tmp; diff $1 $1.tmp; mv $1.tmp $1} `{apply {grep -l oldtext $1} `{du -n | grep -v '^.git'}}
The du command finds all files under the current directory which are not files in the .git directory, or .gitignore.
The grep command lists the file's name if the file contains oldtext.
Apply runs the command in {} for each of the later parameters, one by one, substituting the parameter's value into $1. This $1 is not visible to subshells, which have their own $1, so if we had a {} subcommand inside the apply {}, it would have to refer to the apply block's $1 through an intermediate variable. For example, apply {f=$1; modf=
{echo $f | ...}; ...} *
The sed command updates the file and stores its result in a temporary file.
The diff command shows what was changed.
The mv command can be echoed or omitted until the sed expression is correct.
Written by Jason Catena
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Git
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#