我的代码是
awk '{if (substr($0,81,1)=="1") print substr($0,1,79)"1"; else print $0 }' data > collect_irsc_corrected
awk NF data | awk '{if (substr($0,80,1) == "1") data=substr($0,1,10); if(substr($0,80,1)==""&& substr($0,2,2) != " ") print substr($0,1,15),substr($0,19,10}' > data_irscstation
第二行代码的错误消息是什么意思?awk: line 1: missing ) near }
编辑:这是上面的脚本,它生成格式清晰的错误消息gawk -o-
:
awk '
{
if (substr($0, 80, 1) == "1") {
data = substr($0, 1, 10)
}
if (substr($0, 80, 1) == "" && substr($0, 2, 2) != " ") {
print substr($0, 1, 15), substr($0, 19, 10
}
}
'
这是 gawk 尝试执行该代码时产生的错误消息:
awk: cmd. line:8: print substr($0, 1, 15), substr($0, 19, 10
awk: cmd. line:8: ^ unexpected newline or end of string
希望您能看到调试它比将所有代码塞到一行中要容易得多。
答案1
awk
就像错误消息告诉您的那样,您在函数调用中忘记了最后一个脚本末尾的右圆括号substr($0,19,10)
。