How to group "Only in" lines in diff at the beginning of the output

0

I did:

diff -r directory1/ directory2/

Some files are different, and some files were only in one tree or the other, creating several Only in ... lines.

How do I group these lines at the beginning of the file? I am 99.9% sure that neither directory contains any line that begins with Only in. I was considering something like:

diff -r directory1/ directory2/ | grep -v `^Only in`

But that removes them, rather than groups them. And sort doesn't do what I want either, because I want to keep the actual comparisons in their order.

durron597

Posted 2014-03-18T13:31:56.590

Reputation: 479

Answers

1

One approach might be to redirect the diff output to a file and then use grep to segregate the two parts:

diff -r directory1/ directory2/ > temp
{ grep '^Only in' temp; grep -v '^Only in' temp; } > diff.output

devnull

Posted 2014-03-18T13:31:56.590

Reputation: 2 987

Thanks! Is it possible to do this in one line? Not crucial, just curious. – durron597 – 2014-03-18T13:49:15.147

@durron597 Not any way that I can think of! – devnull – 2014-03-18T13:51:23.353