Mesclar arquivos usando uma coluna comum (awk)

0

Eu tenho dois arquivos de texto:

arquivo 1:

#CHROM  POS ID  REF ALT
1   61442   rs2531261   A   G
1   924629  rs28622096  A   G,T
1   974662  rs2465135   G   T
1   995481  rs9442393   T   G

arquivo 2

#CHROM  POS ID  REF ALT FORMAT
1   61442   rs2531261   A   G   GT:GL:GQ:DP:CGA_RDP:EHQ:HQ:CGA_CEGL:PS:CGA_CEHQ:AD
1   924629  rs28622096  A   G,T GT:GL:GQ:DP:CGA_RDP:EHQ:HQ:CGA_CEGL:PS:CGA_CEHQ:AD
1   974662  rs2465135   G   T   GT:GL:GQ:DP:CGA_RDP:EHQ:HQ:CGA_CEGL:PS:CGA_CEHQ:AD
1   987909  rs34235844  G   GTG GT:GL:GQ:DP:CGA_RDP:EHQ:HQ:CGA_CEGL:PS:CGA_CEHQ:AD
1   995481  rs9442393   T   G   GT:GL:GQ:DP:CGA_RDP:EHQ:HQ:CGA_CEGL:PS:CGA_CEHQ:AD

Eu gostaria de combinar os arquivos com base na coluna 3 (ID). Meu arquivo de saída deve gostar:

saída:

#CHROM  POS ID  REF ALT FORMAT
1   61442   rs2531261   A   G   GT:GL:GQ:DP:CGA_RDP:EHQ:HQ:CGA_CEGL:PS:CGA_CEHQ:AD
1   924629  rs28622096  A   G,T GT:GL:GQ:DP:CGA_RDP:EHQ:HQ:CGA_CEGL:PS:CGA_CEHQ:AD
1   974662  rs2465135   G   T   GT:GL:GQ:DP:CGA_RDP:EHQ:HQ:CGA_CEGL:PS:CGA_CEHQ:AD
1   995481  rs9442393   T   G   GT:GL:GQ:DP:CGA_RDP:EHQ:HQ:CGA_CEGL:PS:CGA_CEHQ:AD

Eu quero usar awk .

    
por June 01.02.2018 / 21:02

1 resposta

2

Parece que você deseja filtrar arquivo2 com base nos IDs no arquivo 1 (em vez de mesclar os arquivos):

$ awk 'NR==FNR {a[$3] = 1; next} $3 in a' file1 file2
#CHROM  POS ID  REF ALT FORMAT
1   61442   rs2531261   A   G   GT:GL:GQ:DP:CGA_RDP:EHQ:HQ:CGA_CEGL:PS:CGA_CEHQ:AD
1   924629  rs28622096  A   G,T GT:GL:GQ:DP:CGA_RDP:EHQ:HQ:CGA_CEGL:PS:CGA_CEHQ:AD
1   974662  rs2465135   G   T   GT:GL:GQ:DP:CGA_RDP:EHQ:HQ:CGA_CEGL:PS:CGA_CEHQ:AD
1   995481  rs9442393   T   G   GT:GL:GQ:DP:CGA_RDP:EHQ:HQ:CGA_CEGL:PS:CGA_CEHQ:AD
    
por steeldriver 01.02.2018 / 21:25