Skip to content
Advertisement

Merge two files using awk in linux

I have a 1.txt file:

JavaScript

A 2.txt file:

JavaScript

FS for 1.txt is “||o||” and for 2.txt is “:” I want to merge two files in a single file result.txt based on the condition that the 3rd column of 1.txt must match with 1st column of 2.txt file and should be replaced by the 2nd column of 2.txt file.

The expected output will contain all the matching lines: I am showing you one of them:

JavaScript

I tried the script:

JavaScript

But getting an empty file as the result. Any help would be highly appreciated.

Advertisement

Answer

If your actual Input_file(s) are same as shown sample then following awk may help you in same.

JavaScript

EDIT: Since OP has changed requirement a bit so providing code as per new ask where it will create 2 files too 1 file which will have ids present in 1.txt and NOT in 2.txt and other will be vice versa of it.

JavaScript
Advertisement