Use printf()
instead of print
, as it doesn’t automatically add a newline. Then you can put a literal \n
in the output. I’ve put this in a variable so I don’t put it before the first line, only all subsequent lines.
Use BEGIN
and END
blocks to print quotes around it.
ssh udcl804 aggr show -root false | awk 'BEGIN {printf "\""; prefix=""}
/^udc/{if($4 >= 80) printf("%s%s", prefix, $0); prefix="\\n"}
END {printf "\""}'
2
solved How to join command output lines into by separating then with \n character [closed]