如果我想将以下awk代码作为python代码执行,那么前进的最佳方法是什么?如果我要使用列表,我将如何弹出列表,以便最终我可以将字段1和3打印回输出列表并将其写入文件。
感谢 格雷厄姆
AWK
#!/bin/awk -f
BEGIN {
FS=":";
}
{
print $1,$3
}
测试文件
Error code 27: This is error code 27:Ihave no comment here
Error code 24: This is error code 27:Ihave no comment here
Error code 27: This is error code 27:Ihave no comment here
Error code 26: This is error code 27:Ihave no comment here
Error code 27: This is error code 27:Ihave no comment here
Error code 29: This is error code 27:Ihave no comment here
Error code 01: This is error code 27:Ihave no comment here
答案 0 :(得分:1)
f = open(file_name)
for line in f:
s = line.split(':')
print s[0],s[2]