LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 12-12-2012, 04:45 AM   #1
r3k
LQ Newbie
 
Registered: Dec 2012
Posts: 2

Rep: Reputation: Disabled
diff -I works unexpected?


Hi

Consider the following two files to be compared

File1
row1 same
row2 diffX
row3 diffY
row4 same
row5 diffZ

File2
row1 same
row2 diffXX
row3 diffYY
row4 same
row5 diffZZ

And then the following comand to compare the files but exclude lines 3 and 5

$ diff -I 'row3' -I 'row5' file1 file2
2,3c2,3
< row2 diffX
< row3 diffY
---
> row2 diffXX
> row3 diffYY

Analysis of the output report
row1 - OK, no diff
row2 - OK, there was a diff and its been reported
row3 - Not OK, there is a diff here yes, but it should be excluded since the -I flag was set
row4 - OK, no diff
row5 - OK, there was a diff but it's been ignored by the -I flag

My conclusion from this is that once a diff is found, the tool ignores all characters until a new row match is found, thus ignoring the -I flag?

To me this looks like unexpected behaviour. What do you guys think?

Regards
r3k
 
Old 12-13-2012, 02:18 AM   #2
cseanburns
Member
 
Registered: Nov 2003
Distribution: Debian
Posts: 117

Rep: Reputation: 17
I don't use diff very often, but it might have something to do with the newline. I modified the two files (below) by adding extra blank lines between each line beginning with '^row' and diff is working as I think you expect it to:

fileA

Code:
row1 same

row2 diffX

row3 diffY

row4 same

row5 diffZ
fileB

Code:
row1 same

row2 diffXX

row3 diffYY

row4 same

row5 diffZZ
And:

Code:
diff -I 'row3' -I 'row5' file1 file2
3c3
< row2 diffX
---
> row2 diffXX
Maybe that will be a clue. Other than that, I'm not sure why the original case isn't working.
 
Old 12-13-2012, 04:43 AM   #3
r3k
LQ Newbie
 
Registered: Dec 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by cseanburns View Post
I don't use diff very often, but it might have something to do with the newline. I modified the two files (below) by adding extra blank lines between each line beginning with '^row' and diff is working as I think you expect it to:

fileA

Code:
row1 same

row2 diffX

row3 diffY

row4 same

row5 diffZ
fileB

Code:
row1 same

row2 diffXX

row3 diffYY

row4 same

row5 diffZZ
And:

Code:
diff -I 'row3' -I 'row5' file1 file2
3c3
< row2 diffX
---
> row2 diffXX
Maybe that will be a clue. Other than that, I'm not sure why the original case isn't working.
I think that the reason your example is working is because the new line is a match. As long as there is at least one line matching directly after a diffed one, the tool will work. The problem is when you have two diffed lines one after another and you are trying to ignore the second one of them with regex. Then it won't work. But in my oppinion, it should.
 
Old 12-13-2012, 08:40 AM   #4
cseanburns
Member
 
Registered: Nov 2003
Distribution: Debian
Posts: 117

Rep: Reputation: 17
Yeah, the intuition does seem to be violated here, but I think I see why now. According to the more detailed explanation of diff options, diff works on hunks. Specifically:
Quote:
In other words, for each nonignorable change, diff prints the complete set of changes in its vicinity, including the ignorable ones.
. See http://www.gnu.org/software/diffutil...pecified-Lines.

Despite that, I wasn't really sure what that meant until I read this explanation from some other forum where someone asked about a similar problem:

Quote:
So here diff processes like this: line "this" needs to be removed
from "a" to match "a1" but since it matches the pattern specified
by -I, ignore it. Line "that" stays untouched, ignore it.
Line "good" needs to be removed from "a" to match "a1", show it.
Lines "this" and "bad" need to be inserted. Although line "this"
should be ignored because it matches the pattern specified
by -I, the very next line, "bad", doesn't match and thus
cannot be ignored, so need to show them both because "for each
nonignorable change, `diff' prints the complete set of changes
in its vicinity, including the ignorable ones." (see 'info diff')
Via http://linux.derkeiler.com/Newsgroup.../msg00307.html
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
setting git-diff --color-words as git-diff potuz Linux - Software 5 09-09-2010 02:31 PM
Strangest FTP error on RHEL5. gFTP works. RHEL4 works too. GuitsBoy Linux - Software 1 04-10-2008 09:29 AM
Mounting works, playing music works, reading tags doesn't Celettu Linux - Newbie 7 08-23-2006 01:27 PM
XAWTV works, videodog works, motion works but how to code my own? rylan76 Linux - Hardware 0 01-06-2006 07:30 AM
Dual Boot diff Hard Disk diff OS on Suse 9.1 wilhem Linux - Newbie 1 08-13-2004 07:06 PM


All times are GMT -5. The time now is 06:12 PM.

Main Menu
Advertisement
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