LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   diff command advice (http://www.linuxquestions.org/questions/linux-newbie-8/diff-command-advice-773611/)

john83reuben 12-05-2009 01:32 AM

diff command advice
 
Hi,

Lets say my file1 contains
john is good. I know!!

and
Lets say my file2 contains
john is bad. I know!!

the diff will gives

Code:

john@john-laptop:~/Desktop/perldir$ diff file1 file2
1c1
< john is good. I know!!
---
> john is bad. I know!!

is there a way to print only the difference, like for example, I wan it to be like this

Quote:

good
bad

Can anyne advice me on this

THanks

JOHn

Vrajgh 12-05-2009 04:37 AM

I haven't managed to reproduce exactly what you are asking for, but wdiff might be a better tool.

Code:

$ apropos wdiff
wdiff (1)            - display word differences between text files

As opposed to diff...
Code:

diff (1)            - compare files line by line
So diff will tell you about lines which have changed and wdiff will tell you about words that have changed. It doesn't place the changes on different lines because it would then not be possible to keep track of which line of the file the changes occured on.

For example with files containing:
file1.txt:
Code:

john is good. I know!!
So is mike

and file2.txt
Code:

john is bad. I know!!
So is bob

Code:

$ wdiff --no-common file1.txt file2.txt

======================================================================
 [-good.-] {+bad.+}
======================================================================
 [-mike-] {+bob+}
======================================================================

You can probably post-process the output with sed or similar to tailor it more to your needs.

john83reuben 12-06-2009 08:50 AM

Thanks Vrajgh for the reply.
Since i am developing a script on a platform which I am not the administrator, so I cant able to install wdiff.

I guess the best way is use the diff command, and the when we get the output.... manipulate the output to get the desired result. In short, i must develop a simple diff kind of script again to manipulate. What you think Vrajgh.

THanks


All times are GMT -5. The time now is 04:31 AM.