Reputation: 45
I am trying using format the output from awk such that the output is delimited by comma. Right now I have this:
ids ="`smartctl -A /dev/ssd |awk '/^[0-9]/ {if ($4 < $6) {print $1}}'`"
and my output looks like this:
111
222
333
but I want something like this:
111,222,333
Also my regex doesn't match with numbers 1 to 99, why?
Upvotes: 2
Views: 128
Reputation: 85913
Just fixed your awk
command to use printf
:
smartctl -A /dev/ssd |awk '/^[0-9]/ {if ($4 < $6){printf "%s%s",sep,$1;sep=","}}'
If you want a trailing newline throw END{print ""}
on the end.
Upvotes: 2
Reputation: 195289
quick and dirty:
your command|awk...|paste -s -d','
e.g:
kent$ paste -s -d',' <<< "a
b
c
d"
a,b,c,d
Upvotes: 3