with open('C:\Users\ehwe\Desktop\INPUT_DS_FILE.txt') as old, open('C:\Users\ehwe\Desktop\OUTPUT_DS_FILE.txt', 'w') as new:
for line in old:
if re.search('trim\(\w+\)',line) == None:
new.write(line)
else:
new_line = re.sub(r"trim\((\w+)\)", r"TRIM (TRIM (CHR (09) FROM \1))", line)
new.write (new_line)
This chunk of code reads line from old file and writes it to a new one. It makes certain modifications according to a pattern.
Problem is - I am not able to run the code - the compiler keeps saying SyntaxError: invalid syntax and highlights the comma in the very first line.
Little help please?
P.S.
the code below works fine (in case someone points out that slashes might go wrong)
with open('C:\Users\ehwe\Desktop\INPUT_DS_FILE.txt') as old:
for line in old:
if re.search('trim\(\w+\)',line) != None:
print 'Y'