Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to get (GNU)DIFF to printout only lines that are different in one file. So given

    ==> diffa.txt <==
    line2 - in a only
    line4 changed

    ==> diffb.txt <==
    line4 changed in b
    line6 in b only

i would like diff --someoption diffa.txt diffb.txt to produce

    line2 - in a only

    line4 changed

The following looks as though it should be helpful but it is a bit cryptic :

          Similar, but format GTYPE input groups with GFMT.

          Similar, but format all input lines with LFMT.

          Similar, but format LTYPE input lines with LFMT.

   LTYPE is `old', `new', or `unchanged'.
          GTYPE is LTYPE or `changed'.

          GFMT may contain:

   %<     lines from FILE1

   %>     lines from FILE2
share|improve this question
The man page is definitely a bit terse on these flags! Good question. –  quickshiftin Oct 18 '13 at 0:01

1 Answer 1

up vote 22 down vote accepted

Not sure diff alone can do it but you can always use the power of other GNU utilities to help you.

diff -u diffa.txt diffb.txt | grep '^-[^-]' | sed 's/^-//'

It does the diff, then selects only the lines that begins with '-' - those are changed and have values from diffa.txt file, then sed just remove those '-' signs.

Edit: After few experiments with diff, looks like the below command produces what you want:

diff --changed-group-format='%<' --unchanged-group-format='' diffa.txt diffb.txt
share|improve this answer
For a one off the pipe method is fine. I would prefer ` perl -ne"print if s/^-//" ` but that is taste. I think I see what --changed-group-format='%<' are doing for me now.... –  justintime Apr 27 '10 at 14:08
Thanks. :D I needed something like this to list all my packages between two computers and I used sdiff but this looks a bit better. –  Rob Sep 21 '11 at 14:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.