开发者

Diff-ing files with Linux command

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.


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


Are you looking for a better diff tool?

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


So, what if A has

 a
 a
 b

and b has

 a
 b

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


Use diff command.

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

Click Here


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜