Merging rows with same id using AWK?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Merging rows with same id using AWK?

I'm trying to merge/concat some rows in a csv-file where the first cells has the same id. For example:

I have these different lines. Their id is the same, so in this case I want to have them all on the same line. I'm quite new to unix, and I really can't figure it out. I tried to modify them with this line, which I found on the homepage: awk -F, '{if(a[$1])a[$1]=a[$1]":"$2; else a[$1]=$2;}END{for (i in a)print i, a[i];}' OFS=, file

0321.2;SCHIEDAM;Spiering, Hendrik;360;;;Delft;Amsterdam;17-05-1625;Texel;;;13-02-1626;Batavia;;Seafarers;116;141;30
0321.2;SCHIEDAM;Spiering, Hendrik;360;;;Delft;Amsterdam;17-05-1625;Texel;;;13-02-1626;Batavia;;Soldiers;45;;
0321.2;SCHIEDAM;Spiering, Hendrik;360;;;Delft;Amsterdam;17-05-1625;Texel;;;13-02-1626;Batavia;;Passengers;10;;

Here's a gist of the entire csv:

I'm sorry if it's not clear, don't really know the right jargon.