Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transpose rows into column in unix

I have input file which is given below

Input file

10,9:11/61432568509
118,1:/20130810014023
46,440:4/GTEL
10,9:11/61432568509
118,1:/20130810014023
46,440:4/GTEL

Output which i am looking for.

10,9:11/61432568509,118,1:/20130810014023,46,440:4/GTEL
10,9:11/61432568509,118,1:/20130810014023,46,440:4/GTEL

I have tried with awk command, but i am not getting desired output. can anyone help me in this?

awk -F"" '{a[$1]=a[$1]FS$2}END{for(i in a) print i,a[i]}' inputfile
like image 917
gyrous Avatar asked Nov 30 '22 03:11

gyrous


1 Answers

Using awk:

$ awk 'ORS=(NR%3==0)?"\n":","' inputfile
10,9:11/61432568509,118,1:/20130810014023,46,440:4/GTEL
10,9:11/61432568509,118,1:/20130810014023,46,440:4/GTEL

EDIT: As commented by sudo_O and Ed Morton, the following variant is more portable:

$ awk 'ORS=(NR%3?",":RS)' inputfile
10,9:11/61432568509,118,1:/20130810014023,46,440:4/GTEL
10,9:11/61432568509,118,1:/20130810014023,46,440:4/GTEL
like image 140
devnull Avatar answered Dec 04 '22 05:12

devnull