Minus operation in two files using Linux commands

I have 4 files sorted alphabetically, A, B, C and D. These files contain one line on each line. Essentially, what should happen is that everything in B is removed from A. The result of this will be stripped of nothing in C. And in a similar way, the result of this will be stripped of D.

Is there a way to do this using Linux commands?

+3
source share
4 answers

comm suitable for this:

cat B C D | sort | comm -2 -3 A -

or

comm -2 -3 A B | comm -2 -3 - C | comm -2 -3 - D

depending on what is simpler and clearer for your script.

+5
source
grep -x -v -f B A | grep -x -v -f C | grep -x -v -f D

-v (.. , ). -f . -x ( , , ).

+2

Look at the team join. Read its man page and you should find what you are looking for.

+1
source
join A B | join - C | join - D
0
source

Source: https://habr.com/ru/post/1716745/


All Articles