输入file.dat
文件:
2017-04-05 16:52:45.564|CN:-|SSLPROTOCOL:TLSv1.2|SSLCIPHER:ECDHE-RSA-AES256-GCM-SHA384|HTTPMETHOD:PATCH|URI:/portal/cache/num_active_capione_nodes|RESPONSETIME:9|STATUS:200|CLIENTIPADDRESS:10.202.30.123|CLIENT:portal-admin@capitalone.com|RESPONSEBODYSIZE:12
输出:我想要用^A
分隔的值,例如:
TLSv1.2 ^A ECDHE-RSA-AES256-GCM-SHA384 ^A PATCH ^A /portal/cache/num_active_capione_nodes ^A 9 ^A 200 ^A 10.202.30.123 ^A portal-admin@capitalone.com ^A 12
答案 0 :(得分:1)
这应该这样做:
with open("foo.dat", "r+") as f:
data = f.read()
data = ata.replace('|', ' ^A ')
f.seek(0)
f.write(data)