I want to compare two files:
For example:
file 1:
1:10471 A/C/G rs1309260800
1:10472 G/T rs1238646298
1:10473 A/G rs1408062762
1:10474 A/T rs1326069208
1:10475 A/T rs1404283754
1:10475 G/T rs1321149898
X:59363536 A/T rs868821995
Y:59363566 G/T rs865996778
file 2:
1:10473 1:10473_G/A
1:13380 1:13380_C/G
1:13380 1:13380_G/C
1:52152 1:52152_ATAAT/A
X:5936355 X:5936355_A/T
when I tried
awk 'FNR==NR{seen[$1]=$0; next} ($1 in seen) {$1=seen[$1]}1' file2 file1
It gives me
1:10471 A/C/G rs1309260800
1:10472 G/T rs1238646298
1:10473 1:10473_G/A A/G rs1408062762
1:10474 A/T rs1326069208
1:10475 A/T rs1404283754
1:10475 G/T rs1321149898
X:59363536 A/T rs868821995
Y:59363566 G/T rs865996778
But I want to get all the matched row and unmacthed rows from file 2. So I change the position of files and tried
awk 'FNR==NR{seen[$1]=$0; next} ($1 in seen) {$1=seen[$1]}1' file1 file2
to get
1:10473 1:10473_G/A A/G rs1408062762
1:13380 1:13380_C/G
1:13380 1:13380_G/C
1:52152 1:52152_ATAAT/A
X:5936355 X:5936355_A/T
But I am not getting this and giving me 0 rows
Can anyone please suggest to me, why is this error happening when I change the position of files in the awk command line