• Post Reply Bookmark Topic Watch Topic
  • New Topic

Format diff output file, suppress-common-lines not working  RSS feed

 
Phoebe Song
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am working on a project that compares 2 files and generates an output, the input file format is this: xxxx xxxxxxxxxxxxxxx yyyyyyyyyyy xxxxxxxxxxxxx xxxxxxxx
I use diff -c -w -B file1 file2 >diff.txt, the output format is this:
file1 xxxx xxxxxxxxxxxxxxx yyyyyyyyyyy xxxxxxxxxxxxx xxxxxxxx
-------------------------------
file2 xxxx xxxxxxxxxxxxxxx zzzzzzzzzzzz xxxxxxxxxxxxx xxxxxxxx

is there a way I can get rid of the common lines, only show the different part? something like

file1 yyyyyyyyyyyyyy
---------------------'
file2 zzzzzzzzzzzzzzzz


I tried diff -y --suppress-common-lines, it is not working. I tried sdiff, it only shows both files first left column even if they are identical.
 
Tim Holloway
Saloon Keeper
Posts: 18799
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The option "-C 0" will suppress context, so the common text before/after the differing lines won't be output. You'd want to play around with other options to fine-tune the output and maybe grep out some stuff. Normally diff is going to at least indicate what line numbers differ.

Another alternative is to get the output in "sed" format (the -e option). In that case, look for lines beginning with nn[,mm]a/d/c, where mm is the (optional) ending line number, and a, d, c are add, delete, change (replace). The new text follows the sed command and is terminated by a line beginning with ".".
 
Phoebe Song
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim, thanks for your help.

I tried "-C 0" option, it is not working. I suspect DOS/Linux version issue.

I am pretty new to Linux, my question is for 2nd option, since all characters are in one line, only white space between those characters, so what's the pattern I am looking for to get the difference part?
 
Tim Holloway
Saloon Keeper
Posts: 18799
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Diff doesn't highlight differences between characters - only differences between lines. You can use the "-w" option on many diff utilities to tell it to ignore whitespace-only differences, if that helps.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!