Hi,
input:
line1|error_type_a@15
line1|error_type_c@10
line1|error_type_b@5
line2|error_type_f@3
line2|error_type_a@1
I would need to place all the second fields with common first field on the same line, BUT with sorted error position number:
line1|error_type_b@5; error_type_c@10; error_type_a@15
line2|error_type_a@1; error_type_f@3
I managed to put in the same line...
BEGIN{FS="|"}
{
a[$1] = a[$1] (a[$1]?"; ":"")$2
}
END{for(i in a){ print i FS a}}'
...but the elements in the new second field are not sorted:
line1|error_type_a@15; error_type_c@10; error_type_b@5
line2|error_type_f@3; error_type_a@1
And when I incorporate the asort function like as follow, it returns a blank second field:
BEGIN{FS=OFS="|"}
{
a[$1] = a[$1] (a[$1]?"; ":"")$2
}
END{for(i in a){
split(a,b,"@");
n = asort(b);
for (j=1; j<=n; j++){
print i FS a[b[j]]
}
}
}'
Any explanation would be great !
Thanks in advance !