Forums Register Login

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

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 ".".
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2046 times.
Similar Threads
diff in two files in UNIX,, help me
renameTo() and delete() not working
file renameTo() method
How to implement the wall follower algorithm in java?
unified format
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 00:26:24.