I have two large files A and B
I need to delete lines that appear in file B from file A and save the result
to file C
I have tried comm -23 file1
As you mentioned, since comm
needs sorted file to fetch the diff you can do in-line sort
ing before using comm like this :
comm -23 <(sort file1) <(sort file2) > fileC
You can use the following:
grep -vxFf fileB fileA > fileC
Sample:
$ seq 5 > a # 1 to 5 in file a
$ seq 10 > b # 1 to 10 in file b
$ grep -vxFf a b > c
$ cat c
6
7
8
9
From man grep
-F, --fixed-strings
Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. (-F is specified by POSIX.)
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. The empty file contains zero patterns, and therefore matches nothing. (-f is specified by POSIX.)
-v, --invert-match
Invert the sense of matching, to select non-matching lines. (-v is specified by POSIX.)
-x, --line-regexp
Select only those matches that exactly match the whole line. (-x is specified by POSIX.)