compare file columns

I need help in file comparision.

I have two files in below format:
FILE_A:
-------
COL1 COL2 COL3 COL4 COL5

FILE_B:
-------
COL1A COL1B COL1C COL1D COL1E

i want to compare for a for each row in FILE_A and FILE_B
COL1 of FILE_A with COL1B of FILE_B
COL3 of FILE_A with COL1E of FILE_B
COL5 of FILE_A with COL1C of FILE_B

and in case they are matching, print the column values COL1 COL2 COL3 from FILE_A into FILE_OK,
and if they do not match then print them into FILE_ERR.txt

for example
FILE_A:
-------
A B C D 1
E F G H 2
I J K L 3

FILE_B:
-------
X E 2 M G
Y A 1 O T
for above two files, first row column of FILE_A (COL1, COL3 and COL5) are matching with
2nd row columns COL1B, COL1E and COL1C respectively of FILE_B, but for second row in FILE_A
they are not matching (COL3 not matching with COL1E).
what is the fastest possible way to do it using awk (or otherwise) ?
if i read line by line, it takes a lot of time as each file contains 50k++ records

Thanks in advance
:slight_smile:

Have you try diff and cmp commands ?

  • nilesh