How do I do a one way diff in Linux?

后端 未结 3 1626
渐次进展
渐次进展 2021-01-13 00:54

How do I do a one way diff in Linux?

Normal behavior of diff:

Normally, diff will tell you all the differences between a two files. For e

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-13 01:27

    An alternative, if your files consist of single-line entities only, and the output order doesn't matter (the question as worded is unclear on this), would be:

    comm -23 <(sort A) <(sort B)
    

    comm requires its inputs to be sorted, and the -2 means "don't show me the lines that are unique to the second file", while -3 means "don't show me the lines that are common between the two files".

    If you need the "differences" to be presented in the order they occur, though, the above diff / awk solution is ok (although the grep bit isn't really necessary - it could be diff A B | awk '/^.

    EDIT: fixed which set of lines to report - I read it backwards originally...

提交回复
热议问题