Linux – comparing column values between two Unix files

linuxtext processing

File A

Table SAPSR3./1BEA/BBEA_BDH has no BasicFile LOB columns
Table SAPSR3./1BEA/BBEA_BDI has no BasicFile LOB columns
Table SAPSR3./1BEA/BBEA_DLI has no BasicFile LOB columns
Table SAPSR3./1BEA/CNPL_PDL has no BasicFile LOB columns
Table SAPSR3./1BEA/CNPL_PLH has no BasicFile LOB columns
Table SAPSR3./1BEA/CNPL_PLI has no BasicFile LOB columns
SAPSR3.RSEUMOD has more than 255 columns

File B

SAPSR3.TERCL2
SAPSR3.TERCL3
SAPSR3.CRM_ACE_UCC
SAPSR3.CRMIOBJCONT
SAPSR3.CRMORDERCONT
SAPSR3.CRMD_WEBREQ_CONT
SAPSR3.CRMIBASECONT
SAPSR3.CRMD_UIF_SYSINDX
SAPSR3.CRMISMCONT

I need to compare the 2nd column from FileA to FileB. If not found, I must print the entire line of fileA into new fileC otherwise (if found) then print the entire line along with concatenated string as "found".

Also from File B, the 1st column must be compared with FileA 2nd column. If not found ,then the result of searching this string (1st column of fileB) concatenated with "Need to be Analysed" must be printed into fileC.

Best Answer

use the amazing tool awk:

awk 'FNR==NR{a[$2]=$3;next}{print $0,a[$2]?a[$2]:"NeedToBeAnalayzed"}' fileA fileB > fileC
Related Question