pgadmin4/pkg/win32/replace.py

37 lines
755 B
Python
Raw Normal View History

import getopt
import sys
2016-06-08 06:29:21 -05:00
# Store input and output file names
infile = ''
outfile = ''
searchExp = ''
replaceExp = ''
2016-06-08 06:29:21 -05:00
# Read command line args
myopts, args = getopt.getopt(sys.argv[1:], "i:o:s:r:")
2016-06-08 06:29:21 -05:00
###############################
# o == option
# a == argument passed to the o
###############################
for o, a in myopts:
if o == '-i':
infile = a
2016-06-08 06:29:21 -05:00
elif o == '-o':
outfile = a
2016-06-08 06:29:21 -05:00
elif o == '-s':
searchExp = a
2016-06-08 06:29:21 -05:00
elif o == '-r':
replaceExp = a
2016-06-08 06:29:21 -05:00
else:
print("Usage: %s -i input -o output" % sys.argv[0])
# Display input and output file name passed as the args
f1 = open(infile, 'r')
f2 = open(outfile, 'w')
for line in f1:
f2.write(line.replace(searchExp, replaceExp))
2016-06-08 06:29:21 -05:00
f1.close()
f2.close()