Re: Is it possible to return the line available in FILE1 but not FILE2 in diff?

Bob Proulx <[email protected]>
Newsgroups gmane.comp.gnu.utils.bugs
Message-ID <[email protected]>
Charles Swiger wrote:
> Peng Yu wrote:
> > I just want to return the line available in FILE1 but not FILE2 in
> > diff. After I read the document, it seems that this is not possible.
> > Could anybody confirm whether this is true? If so, is there an
> > alternative tool that does this? Thanks!
> 
> Using diff will show removed lines with a "-"; otherwise, consider
> using the comm utility since that might be closer to what you want...

You might consider that -u may take an optional number of context
lines to display.

  `-U LINES'
  `--unified[=LINES]'
     Use the unified output format, showing LINES (an integer) lines of
     context, or three if LINES is not given.  *Note Unified Format::.
     For proper operation, `patch' typically needs at least two lines of
     context.

Allowing use like this:

  $ printf "AA\nBB\nCC\n" > 1
  $ printf "AA\nCC\n" > 2
  $ diff -u 1 2
  --- 1      2012-11-13 11:37:56.000000000 -0700
  +++ 2      2012-11-13 11:38:03.000000000 -0700
  @@ -1,3 +1,2 @@
   AA
  -BB
   CC
  $ diff -u0 1 2 | sed "1,2d;/^@@/d"
  -BB
  $ diff -u0 1 2 | sed "1,2d;/^@@/d;s/^-//"
  BB

Bob
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.