简体   繁体   中英

awk statement to get output in one line

Please suggest -

Input File -

G238740
G316342
G748951
G952443
G955221
G952842
G767727
G339717
G712953 

Command i tried:

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

Current output -

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

Desired output , How to get output in one single line

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

Use printf instead of print , so it won't add a newline. And then conditionally print the || separator on all lines but the first:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM