csv - Seperate values with commas on one line from a variable BASH -
i have bash script stores values in variable , outputs each value on separate line this:
2288 87 183 30 16 i need values in format on 1 line can export csv:
2288, 87, 183, 30, 16 i have looked @ examples online of using sed or awk couldn't find example similar mine
any appreciated
paste friend:
$ paste -s -d',' file 2288,87,183,30,16 you can use tr or awk, trailing comma:
$ awk '{printf $0","}' file 2288,87,183,30,16, $ tr -s '\n' ',' <file 2288,87,183,30,16, update
its not file variable have doesn't appear work in same way?
kind of:
$ myvar="2288 87 183 30" $ echo "$myvar" | paste -s -d',' 2288,87,183,30 $ echo "$myvar" | tr -s '\n' ', ' 2288,87,183,30, $ echo "$myvar" | awk '{printf $0","}' 2288,87,183,30,
Comments
Post a Comment