Any idea to convert the given line below into Python?
sed 's+forwarding_link+'$link'+g' first.html > index2.html
Any idea to convert the given line below into Python?
sed 's+forwarding_link+'$link'+g' first.html > index2.html
with open('first.html') as infile:
data = infile.read()
data = data.replace('forwarding_link', link)
with open('index2.html', 'w') as outfile:
outfile.write(data)
This might useful
Since link
is a variable, it will stay as such in Python
You will have to read the file first.html
, use string.replace
to replace the matching strings, and then dump the result into index2.html
.
link = 'your link here'
with open('first.html') as infile:
data = infile.read()
data = data.replace('forwarding_link', link)
with open('index2.html', 'w') as outfile:
outfile.write(data)