import codecs infile = codecs.open("hashplain.txt" , "r", encoding="utf8", errors="replace") outfile = codecs.open("parsed.txt" , "w", encoding="utf8", errors="replace") for x in infile: x = x.split(":") x[2] = bytes.fromhex(x[2].replace("$HEX[", "").replace("]", "")).decode("ASCII")[:-1] y = x[0] + ":" + x[1] + ":" + x[2] outfile.write(y)