LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

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

Rep: Reputation: 17
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
 
Old 12-05-2009, 04:37 AM   #2
Vrajgh
Member
 
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.

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.
 
Old 12-06-2009, 08:50 AM   #3
john83reuben
Member
 
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.

THanks
 
  


Reply


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


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 12:23 PM.

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