Text Processing: Grep - compare two files
From WikiMLT
Source of the article: Ask Ubuntu: Comparing contents of two files.
Get only the lines that exist in file1
but not in file2
:
grep -Fxvf file2 file1 > diff_file
Where:
-F
,–fixed-strings
– PATTERNS are strings,-x
,–line-regexp
– match only whole lines,-v
--f
-
An inline script for two ways comparison:
FILE1="file1"; FILE2="file2"; \
cat <(echo -e "\nOnly in $FILE1") \
<(grep -Fvxf "$FILE2" "$FILE1") \
<(echo -e "\nOnly in $FILE2") \
<(grep -Fvxf "$FILE1" "$FILE2")