cat file
AirIfLoadProfile trafficModelPrb ulDlRatioPerQci
EUtranCellTDD servOrPrioTriggeredErabAction 1
当我执行命令时:
awk '($NF!~/^[0-9]+$/)?{printf("%s,%s,%s",$1,$2.$3)}:{printf("%s,%s,%s",$1,$2,$3)}' file
出现以下错误:
awk: cmd. line:1: ($NF!~/^[0-9]+$/)?{printf("%s,%s,%s",$1,$2.$3)}:{printf("%s,%s,%s",$1,$2,$3)}
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: ($NF!~/^[0-9]+$/)?{printf("%s,%s,%s",$1,$2.$3)}:{printf("%s,%s,%s",$1,$2,$3)}
awk: cmd. line:1: ^ syntax error
请帮我找一下格式问题。
答案 0 :(得分:1)
正确的方式:
awk '{ printf("%s %s%s%s\n",$1,$2,($NF~/^[0-9]+$/? " ":"."),$3) }' file
%s
接受条件($NF~/^[0-9]+$/? " ":".")
输出:
AirIfLoadProfile trafficModelPrb.ulDlRatioPerQci
EUtranCellTDD servOrPrioTriggeredErabAction 1