Visit the LQ Articles and Editorials section
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


LinkBack Search this Thread
Old 12-05-2009, 01:32 AM   #1
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 132

Rep: Reputation: 17
diff command advice


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

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

the diff will gives

john@john-laptop:~/Desktop/perldir$ diff file1 file2
< 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


Can anyne advice me on this


Old 12-05-2009, 04:37 AM   #2
Registered: Aug 2005
Posts: 65

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

$ apropos wdiff 
wdiff (1)            - display word differences between text files
As opposed to diff...
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:
john is good. I know!!
So is mike
and file2.txt
john is bad. I know!!
So is bob
$ 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.
Old 12-06-2009, 08:50 AM   #3
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 132

Original Poster
Rep: Reputation: 17
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.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
What is wrong with this diff command? jb_get Linux - Newbie 2 10-01-2008 08:27 AM
Question on diff command just.srad Programming 4 04-05-2008 04:01 AM
How to use 'diff' command ursusman Linux - Newbie 1 03-08-2007 04:29 AM
help on diff command anandss2004 Programming 2 11-01-2005 12:58 PM
the diff command or any other similar things murshed Linux - Newbie 4 02-12-2003 10:07 PM

All times are GMT -5. The time now is 01:21 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration