sed in python

PHOTO EMBED

Thu Jul 14 2022 14:38:45 GMT+0000 (Coordinated Universal Time)

Saved by @quaie #python

# sed workaround, shamelessly stolen & modified
# from https://raw.githubusercontent.com/mahmoudadel2/pysed/master/pysed.py
def replace(oldstr, newstr, infile):
    linelist = []
    with open(infile) as f:
        for item in f:
            newitem = re.sub(oldstr, newstr, item)
            linelist.append(newitem)
    with open(infile, "w") as f:
        f.truncate()
        for line in linelist: f.writelines(line)
content_copyCOPY

https://raw.githubusercontent.com/mahmoudadel2/pysed/master/pysed.py