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
diff A B|grep '^<'|awk '{print $2}'
grep '^<'
means select rows start with <
awk '{print $2}'
means select the second column
As stated in the comments, one mostly correct answer is
diff A B | grep '^<'
although this would give the output
< good dog
< two
rather than
2c2
< good dog
4c4,5
< two
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 '/^</ { $1 = ""; print }'
.
EDIT: fixed which set of lines to report - I read it backwards originally...