awk to separate rows from bed files depending on character

42 Views Asked by At

I want to separate rows by comma delimiter in one filed and keep the other information of the row. I have tab delimited files with 4 columns and a lot of rows...

Frome here:

1 13445 rs558318514 C   G,T 1_13445

1 13453 rs568927457 T   C   1_13455

1 13483 rs554760071 G   A,C 1_13483

1 13550 rs554008981 G   A   1_13550

To here:

1   13445   rs558318514 C   G   1_13445

1   13445   rs558318514 C   T   1_13445

1   13453   rs568927457 T   C   1_13453

1   13483   rs554760071 G   A   1_13483

1   13483   rs554760071 G   C   1_13483

1   13550   rs554008981 G   A   1_13550
1

There are 1 best solutions below

0
On
$ awk '{n=split($5,a,","); for(i=1; i<=n; i++){$5=a[i]; print}}' file
1 13445 rs558318514 C G 1_13445
1 13445 rs558318514 C T 1_13445
1 13453 rs568927457 T C 1_13455
1 13483 rs554760071 G A 1_13483
1 13483 rs554760071 G C 1_13483
1 13550 rs554008981 G A 1_13550