regex - How to convert this sed command to Python script? -
i have 1 old shell script include sed command below. source data($tmp) html table.
sed '/<table border/,/table>/d' $tmp > $out
can me convert command python script? can't figure out how regular expression. many thanks..
the script copys lines input file output file, unless finds line containing <table border
, deletes lines until finds /table>
, continues writing further lines.
so 1 possibility be:
with open('in') inf, open('out', 'w') outf: while true: line = inf.readline() if '<table border' in line: while true: line = inf.readline() if not line or '/table>' in line: line = inf.readline() break if not line: break outf.write(line)
Comments
Post a Comment