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

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -