3

What Linux command allow me to check if all the lines in file A exist in file B? (it's almost like a diff, but not quite). Also file A has uniq lines, as is the case with file B as well.

5 Answers 5

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

Are you looking for a better diff tool?

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

Comments

1

So, what if A has

 a
 a
 b

and b has

 a
 b

What would you want the output to be(yes or no)?

Comments

1

Use diff command.

Here is a useful vide with complete usage of diff command under 3 min

Click Here

Comments

0
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 each line will have a 2 in front if it). This relies on the lines in A being unique, and the lines in B being unique.

If they aren't, and you don't care about counting duplicates, it's relatively simple to transform each file into a list of unique lines using sort and uniq.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.