Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove duplicates respecting linebreaks?

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading