awk语句获取一行输出

时间:2015-03-31 06:24:51

标签: awk

请建议 -

输入文件 -

G238740
G316342
G748951
G952443
G955221
G952842
G767727
G339717
G712953 

命令我试过:

 awk -F";" '{ print "displayName == \""$1"\" " "||" }' input

当前输出 -

displayName == "G238740" ||
displayName == "G316342" ||
displayName == "G748951" ||
displayName == "G952443" ||
displayName == "G955221" ||
displayName == "G952842" ||
displayName == "G767727" ||
displayName == "G339717" ||
displayName == "G712953" ||

所需的输出,如何在一行中获得输出

displayName == "G238740" || displayName == "G316342" || displayName == "G748951"

1 个答案:

答案 0 :(得分:2)

使用printf代替print,因此不会添加换行符。然后有条件地在所有行上打印||分隔符,但第一行:

awk '{printf("%sdisplayName == \"%s\"", (NR == 1 ? "" : " || "), $1)}
    END {print ""}' input