Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 2 files that I want to differ. File B is produced appending some new line to file A. I want to highlight the appended data by using diff.

I would like to avoid printing out the '>' characters and the '10a11,14' of the output below.

Reading the man pages of diff I can see that you can specify the formatting of the result ( LFMT ) but I am struggling in producing something useful.

Could you help in removing those characters I don't need?

Regards

AFG

   diff --left-column A.txt  B.txt

   10a11,14
   > TXT :   some text
   >         some text
   >         some text
   >         some text
share|improve this question
up vote 3 down vote accepted

There are two easy ways of doing this, you can either parse the output of diff or you can use comm.

  • diff fileA fileB | grep '>' | sed 's/> *//'

  • comm -13 fileA fileB

share|improve this answer
    
it works nicely! Thanks a lot! – Abruzzo Forte e Gentile Feb 15 '13 at 10:51
    
diff also handles the -u (unidiff) format, it is easier on the eyes. – vonbrand Feb 15 '13 at 19:36

Although more typing than just using comm, the following provides a demonstration of the --GTYPE-group-format options:

diff --unchanged-group-format="" --new-group-format="%>" A.txt B.txt

This commmand would only print those lines in B.txt and not in A.txt. The first option suppresses common lines. There's no need to use --changed-group-format (no lines that have different values in each file) or --old-group-format (everything in A.txt is also in B.txt).

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .