import os import re for file in os.listdir("."): if not file.endswith(".bench"): continue content = open(file, "r").read() content = re.sub(r"(\d+)", r"\\\1", content) print(content) f = open("new/" + file, "w") f.write(content) f.close()