|
@@ -0,0 +1,16 @@
|
|
|
+import glob
|
|
|
+import fileinput
|
|
|
+import sys
|
|
|
+
|
|
|
+if len(sys.argv) != 4:
|
|
|
+ print("Usage: python3 replace.py [files_pattern] [old_string] [new_string]")
|
|
|
+ sys.exit(1)
|
|
|
+
|
|
|
+pattern = sys.argv[1]
|
|
|
+old_string = sys.argv[2]
|
|
|
+new_string = sys.argv[3]
|
|
|
+
|
|
|
+for file in glob.glob(pattern):
|
|
|
+ with fileinput.FileInput(file, inplace=True) as f:
|
|
|
+ for line in f:
|
|
|
+ print(line.replace(old_string, new_string), end='')
|