Last active
June 30, 2018 08:20
-
-
Save shavidzet/9f20e734d118dbf81e70f32c18d81e03 to your computer and use it in GitHub Desktop.
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
import os, fnmatch | |
def findReplace(directory, find, replace, filePattern): | |
for path, dirs, files in os.walk(os.path.abspath(directory)): | |
for filename in fnmatch.filter(files, filePattern): | |
filepath = os.path.join(path, filename) | |
with open(filepath) as f: | |
s = f.read() | |
s = s.replace(find, replace) | |
with open(filepath, "w") as f: | |
f.write(s) | |
findReplace("/dir", "foo", "bar", "*.js") |
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
find ./ -type f -exec sed -i ‘s/string1/string2/’ {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment