Skip to content
Advertisement

Awk asking combine two files

I have combined two different files with Same Key by AWK command. And In case there is no key match compare to File1 and File2 then just put “ttt” instead.

I have below AWK command.

JavaScript

Example Combine File1

JavaScript

File2

JavaScript

Then Expected result

JavaScript

My AWK Command Show

JavaScript

I already tried to do few way like below

JavaScript

But looks like this is does not cover all cases. Anyone has better idea to do this? Thank you!

Advertisement

Answer

This solution doesn’t hardcode that there are 3 extra fields in File2

JavaScript

The output looks a bit odd due to how stackoverflow displays tabs

JavaScript

To fix your code, you need to keep track of the keys in file2 that update the results. Change

JavaScript

to

JavaScript

and, in the END block, change

JavaScript

to

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement