I searched the forum and tried to learn from the similar posts. However, I am new and I need to get help on this. I hope an expert kindly help me to sort this out.
I need to compare field 1 and 2 of the first file with the same fields of the second file and if both fields matches insert the field 9 and 10 of the second file to the position 1 and 2 of the first file.
Good point, but in my defense the original request wasn't specific about what should be output when a match wasn't found. It's probably slightly safer to put blank values for 9 and 10 rather than hiding the whole row.
BTW, I also considered a for loop to print the headings, but I suspect the real data has no headings or data specific headings that the OP renamed for ease of reference.
Great idea to use 9 OFS 10 as the hash array data.
the fields that added to my fileA aren't correct. Something must be wrong with it. I test your codes with headings and let you know if it works.
Thanks again!
Be careful you put the files on the awk command line in the correct order (FileB = your 2nd file) (fielA = your 1st file).
Here is a transcript of my test (with slight enhancement - Use FS instead of "|" in array index - thanks rdcwayx).
I kept the two arrays as this ensures the output has the same number of fields when lookup of fields1 and 2 don't find any data.
Thank you very much Chubler XL . I tested it again and I found that your code is working flawlessly and the problem is with my data. Actually, both files are space-delimited but the spacing between the feilds are not the same. That's why in some cases the other feilds are printing insead of feild 9 and 10.
Is there a way to overcome this problem?
---------- Post updated at 09:57 PM ---------- Previous update was at 09:43 PM ----------
Thank you very much rdcwayx.
Your code is just awesome! It read and printed my huge file in a second!
However, as the spacing between fields are not regular, wrong fields are printed for some rows. I think I should do something for my irregular fileA first.