grep: compare two unsorted files and get unique lines
Scenario: every day we run a report that produce a csv file with some IDs and we want to check the differences that those two files might…
Scenario: every day we run a report that produce a csv file with some IDs and we want to check the differences that those two files might have, we need to check if there are missing IDs from the previous day CSV vs the current day CSV and vice versa.
The contents of the previous day file: previous.txtAAA1
BBB1
CCC1
DDD1
The contents of the current day file: current.txtAAA1
BBB1
DDD1
EEE1
- To find if there is an ID in the previous day file that does not exist in the current day file.$ grep -Fxv -f current.txt previous.txt
CCC1
2. To find If there is in ID in the current day file that does not exist in the previous day file.$ grep -Fxv -f previous.txt current.txt
EEE1
Explaination of the parameters:-F:Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched.
-x: exact match
-v: invert match results
-f: files to grep