I'm still learning programming and I've tried many things but just cannot get the correct format. I have a tab delimited file with 17 columns and many (around 50.000) rows. The file is already sorted by first column. I want to merge rows that have the same first column (A), but all other 16 columns are different and I want to keep all the information in one row, preferably in the same column with semicolon ; as a delimiter between them. I want to keep tab as a delimiter in the output file. Thank you so much for the answers and if you could also explain the answer where I went wrong that would be even better :).
I've tried so far:
awk -F'\t' 'NF>1{a[$1] = a[$1]";"$2}END{for(i in a){print i""a[i]}}' filename.txt
perl -F',' -anle 'next if /^$/;$h{$F[0]} = $h{$F[0]}.", ".$F[1];
END{print $_,$h{$_},"\n" for sort keys %h}' filename.txt
FILE FORMAT (other 15 columns have the same format as column B)
A B C
123 fvv ggg
123 kjf ggg
123 ccd att
567 abc gst
567 abc hgt
879 ttt tyt
The output I want (I need all 17 columns and for columns 2-16 I need the same output as in column B and C). All cases of B should be under B and all cases of C should be under C and all cases of D should be under D etc. So the output has 17 columns just like the input and instead of 50.000 rows, it now should have around 20.000, because there are many repeats for column 1 (for this particular file):
A B C
123 fvv;kjf;ccd ggg;ggg;att
567 abc;abc gst;hgt
879 ttt lll
sed ':1;$!N;s/^\(\(\S\+\s\+\).*\)\n\2/\1;/;t1;P;D' filename.txt
gnu datamash
e.g. assuminginfile
is sorted by 1st column you could run{ head -n 1; datamash -g 1 $(printf 'collapse %s ' {2..15}); } <infile | column -t