Diff files with Linux command

Which Linux command allows me to check if all lines in file A in file B exist? (this is almost like a difference, but not quite). File A also has uniq lines, as is the case with file B.

+3
source share
5 answers

The comm command compares two sorted files line by line and is part of the GNU coreutils.

+3
source

Are you looking for the best comparison tool?

https://stackoverflow.com/questions/12625/best-diff-tool

+1
source

, , A

 a
 a
 b

b

 a
 b

, ( )?

+1

diff.

diff 3

+1
if cat A A B | sort | uniq -c | egrep -e '^[[:space:]]*2[[:space:]]' > /dev/null; then
   echo "A has lines that are not in B."
fi

If you do not redirect the output, you will get a list of all the lines that are in A that are not in B (except that each line will have a 2front if it is). This depends on the lines in B being unique and the lines in B being unique.

If this is not the case, and you do not care about counting duplicates, it is relatively easy to convert each file to a list of unique lines using sortand uniq.

0
source

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


All Articles