I have two files as below and I want to merge them into one file based on common IDs:
File1:
ARS 8.0 8.0
BBL 1.1 1.2
CCL 1.9 1.8
File2:
ARS 2.3 2.4
ARS 2.6 2.4
ARS 2.5 2.3
BBL 1.9 1.8
EDE 1.4 1.6
Desired output:
ARS 8.0 8.0 ARS 2.3 2.4
ARS 8.0 8.0 ARS 2.6 2.4
ARS 8.0 8.0 ARS 2.5 2.3
BBL 1.1 1.2 BBL 1.9 1.8
CCL 1.9 1.8 NA
NA EDE 1.4 1.6
Could you please try following and let me know if this helps you.(I have kept the order of NA at last only let me know if this helps you). Adding a non-one liner form of solution too here.
Output will be as follows.
There is a tool for merging files
output:
.
There's various ways it could be optimized to not store the whole contents of both files in arrays but I like the simplicity and symmetry of the above and it's trivial to optimize later if that proves to be necessary due to massive input files.