Last active
October 14, 2019 20:14
-
-
Save linknum23/1ee47cf68715f8ba0721864cfe17889e to your computer and use it in GitHub Desktop.
Advanced find and replace/prepend with sed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# these ideas was used during conversion from C code to C++ | |
directory_whitelist="dir1 dir2" # directories to replace files in | |
for dir in $(directory_whitelist); do | |
pushd $dir; | |
# do replacement but use prefix to make sure replacement only happens once (in this case prepending std::) | |
# \1 in the replace portion of the sed command is used to keep the character before the match (typically a space or '(') | |
# otherwise that character will get overwritten with the replacement | |
grep -rl --include={*.h,*.cpp} "[^std::]abs(" | xargs -i@ sed -i 's/\([^std::]\)abs(/\1std::abs(/g' @; | |
popd; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment