From: Oleg Broytman Date: Sun, 17 Jul 2016 02:11:00 +0000 (+0300) Subject: bin/replace: option -i to ignore case X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=b87a266df1e0dad5914ecafebde2c3615a0133f3;p=dotfiles.git bin/replace: option -i to ignore case --- diff --git a/bin/replace b/bin/replace index 166eb57..8ff7124 100755 --- a/bin/replace +++ b/bin/replace @@ -3,15 +3,21 @@ 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)