Reputation: 99
I have a Unix file which has data like this.
1379545632,
1051908588,
229102020,
1202084378,
1102083491,
1882950083,
152212030,
1764071734,
1371766009,
(FYI, there is no empty line between two numbers as you see above. Its just because of the editor here. Its just a column with all numbers one below other)
I want to transpose it and print as a single line.
Like this:
1379545632,1051908588,229102020,1202084378,1102083491,1882950083,152212030,1764071734,1371766009
Also remove the last comma.
Can someone help? I need a shell/awk solution.
Upvotes: 2
Views: 3931
Reputation: 11
awk 'BEGIN { ORS="" } { print }' file
ORS : Output Record separator. Each Record will be separated with this delimiter.
Upvotes: 1
Reputation: 203597
With GNU awk for multi-char RS:
$ printf 'x,\ny,\nz,\n' | awk -v RS='^$' '{gsub(/\n|(,\n$)/,"")} 1'
x,y,z
Upvotes: 1
Reputation: 249153
tr '\n' ' ' < file.txt
To remove the last comma you can try sed 's/,$//'
.
Upvotes: 3