how to check if a field in one file does not contain list of values from another file in UNIX

339 Views Asked by At

I have two files, one has the data that is transactional value for that column. Suppose currency code and the another file has the valid/expected currency code.

File1 :

ID|col1|curr_cd

1|abc|INR

2|def|USD

3|xyz|3AB

4|tuv|ABC

....

File2

curr_cd

INR

USD

CAD

....

I need the list of values those are invalid, which means is present in File1 but is not present in File2. File1 may contain millions of transactions, so I need an AWK or a command that could give me the result faster.

Can anyone help me here please.

1

There are 1 best solutions below

1
ruggierom On
# Returns whole row
fgrep -vf file_2 file_1

# Returns just the bad value
fgrep -vf file_2 file_1 | awk -F '|' '{print $2}'