-
-
Save theirishpenguin/1705634 to your computer and use it in GitHub Desktop.
Recursively replace files in the current directory and subdirectories using regular expressions
This file contains hidden or 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
# Usage | |
# (Note: This command does not handle spaces in filenames!) | |
# * cd into the directory containing the files and subdirectories of files in | |
# which you wish to carry out string substitution using a regex | |
# * Run the command: | |
# rsub 'search regex' 'replacement text' | |
# * This will effect the desired substitution in files in the current directory | |
# and in any subdirectories | |
# Explaination | |
# * The -I {} allows you to grab each thing that xargs iterates over | |
# as {} | |
# * So {} is probably the most important thing | |
# | |
egrep -rl "$1" .|xargs -I {} sed -i "s/$1/$2/g" {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment