import sys
if len(sys.argv) < 4:
- sys.stderr.write("Usage: %s from_re to_re file....\n" % sys.argv[0])
+ sys.stderr.write("Usage: %s [-i] from_re to_re file....\n" % sys.argv[0])
sys.exit(1)
import re
-search = re.compile(sys.argv[1])
-replace = sys.argv[2]
+if sys.argv[1] == '-i':
+ search = re.compile(sys.argv[2], re.IGNORECASE)
+ replace = sys.argv[3]
+ start = 4
+else:
+ search = re.compile(sys.argv[1])
+ replace = sys.argv[2]
+ start = 3
from fileinput import FileInput
-files = FileInput(sys.argv[3:], inplace=1)
+files = FileInput(sys.argv[start:], inplace=1)
for line in files:
line = search.sub(replace, line)