I need to print the lines of one document if they match with the first column of the second file, using AWK.
FIRST FILE (comprobacio.txt):
2187405XJ4228N0001RX
42379999999997GH0002
517878G4RSD407yJK4NY
4237405HHYT4323H0002
517P0P0P06GH9001233F
517878G4R67TRRHOPPNY
423123R66677789323H2
SECOND FILE (datos.txt):
2187405XJ4228N0001RX@1984@216@230 08m 06s N, 82o 21m 34s W
4237405XJK4N37GH0002@2010@54@400 02m Ols N, 80o 20m 12s W
517878G4RSO405XJK4NY@1954@103@400 42m 51s N, 74o 06m 21s E
4237405HHYT4323H0002@2006@55@300 04m Ols N, 810 20m 12s W
517POLIJ56GH9001233F@2010@803@400 52m 52s N, 74o 06m 70s E
517878G4R67TRRHOPPNY@1954@108@400 42m 51s N, 74o 05m 21s E
4237405899544T4323H2@2000@5778@390 12m 07s N, 900 10m 12s W
OUTPUT EXPECTED
2187405XJ4228N0001RX@1984@216@230 08m 06s N, 82o 21m 34s W
4237405HHYT4323H0002@2006@55@300 04m Ols N, 810 20m 12s W
517878G4R67TRRHOPPNY@1954@108@400 42m 51s N, 74o 05m 21s E
I have tried first editing the second files with sed to eliminate the '@' character and replace it with a space ' '. And pipe it after it with AWK to come up with the lines that have the same first column but it doesn't output anything.
sed 's/@/ /g' datos.txt | awk 'FNR==NR{array[$1];next} $1 in array {print $0}' datos.txt comprobacio.txt
Any idea of what I'm getting wrong?