1

Any idea to convert the given line below into Python?

sed 's+forwarding_link+'$link'+g' first.html > index2.html
TylerH
  • 20,799
  • 66
  • 75
  • 101
Adarsh
  • 25
  • 4

2 Answers2

1
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

Adarsh Raj
  • 325
  • 4
  • 17
0

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)
Tushar Sadhwani
  • 414
  • 4
  • 7