Issue
I am using this answer for removing duplicates from two files. Suppose file1
consists of the following:
a
b
c
d
and file2:
a
b
c
cd
z
after running:
grep -F -v -f file1 file2 > file3
I get this in file3:
z
I understand why it removes the line consisting cz
, but I want to stop that behavior. How to do that?
sed
-solutions are also welcome. I have tried the following from this answer with the same effect in file3
:
sed $(awk '{printf("-e /%s/d ", $1)}' file1) file2 > file3
Solution
To remove lines present in one set from lines present in another file, you would:
comm -13 <(sort file1) <(sort file2)
How to do that?
Use -x
to match the whole line.
Answered By - KamilCuk Answer Checked By - Mildred Charles (WPSolving Admin)