I have a text file as shown below
15
5
10
25
35
12
I would like to arrange the above numbers as shown below. How can I do this with awk or sed?
Desired output
15,5,10,25,35,12
I have a text file as shown below
15
5
10
25
35
12
I would like to arrange the above numbers as shown below. How can I do this with awk or sed?
Desired output
15,5,10,25,35,12
Through sed,
$ sed ':a;N;$!ba;s/\n/,/g' file
15,5,10,25,35,12
Through awk,
$ awk -v RS= '{gsub(/\n/,",")}1' file
15,5,10,25,35,12
Here are some versions:
awk '$1=$1' RS= OFS=, file
15,5,10,25,35,12
paste -d, -s file
15,5,10,25,35,12