pythonsedcode-conversion

How to use/convert sed to Python?


Any idea to convert the given line below into Python?

sed 's+forwarding_link+'$link'+g' first.html > index2.html

Solution

  • 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