re.search - just skip it
Input is this: SET1_S_W CHAR(1) NOT NULL, SET2_S_W CHAR(1) NOT NULL, SET3_S_W CHAR(1) NOT NULL, SET4_S_W CHAR(1) NOT NULL, ; .py says: import re, string, sys s_ora = re.compile('.*S_W.*') lines = open("y.sql").readlines() for i in range(len(lines)): try: if s_ora.search(lines[i]): del lines[i] except IndexError: open("z.sql","w").writelines(lines) but output is: SET2_S_W CHAR(1) NOT NULL, SET4_S_W CHAR(1) NOT NULL, ; It should delete every, not every other! thx, RasDJ -- http://mail.python.org/mailman/listinfo/python-list
next line, new line
I have a lot of SQL to convert to postgres from oracle. I have most of the problems worked out except for this last bit. Many of my tables need the last comma replaced with a close parenthesis - they look like this: create table schema.table ( FLD000 NUMERIC(10,0) NOT NULL, FLD001 CHAR(3) NOT NULL, FLD002 DATE NOT NULL, ; when the syntax requires: FLD002 DATE NOT NULL) ; I output the text in reverse thinking I could find the semicolon, go to the next line and replace the 'comma newline' with 'closeparen newline' and then go on to find the next semicolon. ; FLD002 DATE NOT NULL, FLD001 CHAR(3) NOT NULL, FLD000 NUMERIC(10,0) NOT NULL, create table schema.table ( ; FLD002 DATE NOT NULL, FLD001 CHAR(3) NOT NULL, FLD000 NUMERIC(10,0) NOT NULL, create table schema.table2 ( I don't seem to be making any progress altho I have had some interesting output. Throw me a bone? Thank you, RasDJ -- http://mail.python.org/mailman/listinfo/python-list
Re: next line, new line
Thanks Jeremy, something like this would work: try: lines = [ line.replace(",\n;", ")\n;") for line in input ] If I could figgure out how to: IF ':' in line READ next line in lines = [ line.replace(",\n;", ")\n;") for line in input ] output.write(str.join('', lines)) because there are lots of "comma newline" but the only ones I want are the ones that follow the semicolon. RasDJ -- http://mail.python.org/mailman/listinfo/python-list