Append last two field with the same id

Hi everybody!! I am new on this forum and I really hope that you can help me!
My problem concern the editing of a file like this:

chr1    23254208        23274520        1,9 0,5        no      chr1    23252345        2722460        h3k27me3        -4,3
chr1    23254208        23274520        1,9 0,5        no      chr1    243656645 43692360        h3k9ac  0,66
chr1    23254208        23274520        1,9 0,5        no      chr1    23256645        23292360        h3k9me3 -5,54
chr1    23254578        23274768        16,1 1,2 yes chr1    23243645        23292360        h3k27me3        -4,33
chr1    23254578        23274768        16,1 1,2 yes      chr1    23256645        2334360        h3k4me3 -1,11

What I would like to obtain is a file like this (followed by explanation):

chr1    23254208        23274520        1,9 0,5        no      chr1    23252345        2722460        h3k27me3        -4,3        h3k9ac  0,66        h3k9me3 -5,54
chr1    23254578        23274768        16,1 1,2 yes chr1    23243645        23292360        h3k27me3        -4,33 h3k4me3 -1,11

I want to compare the first 3 fields of each row and, if they are identical, I want to print all the first row followed by the last two field of the same/followed row. I really hope my explanation is satisfying!!
Thank a lot

Giuliano

Try this:

awk '{x=$1$2$3; a[x]=a[x]?a[x] FS $10 FS $11:$0} END {for(i in a) print a}' file
1 Like

Thanks Subbeh!
It works perfectly!
:b::b::b:

How about this ? with assumption file is sorted

$ awk '{printf p == $1$2$3 ? NR == 1 ? $0 : OFS $10 OFS $11 : RS $0 }{p = $1$2$3}END{printf RS}'  file