Merge two texts with comparison of the rows and select one text's rows if some columns are similar
I have two different files which some rows of the two data measures a same thing. I want to have a merged output such that the rows of File1 will be the output row where the rows measures same thing (second row of file1 and first line of file2 measures same thing. I want to have the file1 first line when column1 and column2 of the files are similar.)
... File1:
1257, OBM , 47, 106, 1330
1257, IRK , 52, 104, 467
....
File2:
1257, IRK , 50, 100, 400
1000, CTK , 47, 106, 1330
....
output:
1257, OBM , 47, 106, 1330
1257, IRK , 52, 104, 467
1000, CTK , 47, 106, 1330
....
Use `awk`:
awk -F',' '!seen[$1,$2]++' file1 file2
**Explanation:**
* In the beginning, the array item with key being fields `$1,$2` is unassigned, thus false.
* If it's false, `!seen` is true, so we increment it (make it true) and do the default action which is `print`.
* If it's true (second time we see the same fields) `!seen` is false and `awk` will skip that line.