LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 05-29-2009, 06:34 AM   #1
nemobluesix
LQ Newbie
 
Registered: May 2008
Distribution: fedora
Posts: 13

Rep: Reputation: 0
Question selective diff and patch


Hi,

I'm trying to use diff with the "-I regexp" option but it doesn't work as it should.
I have two files and I want to modify one of them but leave some of the lines unchanged.

File "input.xml" is a file that from time to time gets modfied.
Code:
<root>
        <group>
                <name>some name 1</name>
                <custom>some default text 1</custom>
                <missing>some other text 1 missing from template</missing>
        </group>
        <group>
                <name>some name 2</name>
                <custom>some default text 2</custom>
                <missing>some other text 2 missing from template</missing>
        </group>
</root>
File "template.xml" is a file created based on "input.xml" and should be updated every time "input.xml" is changed.
Code:
<root>
        <group>
                <name>some name 1</name>
                <custom>some custom text 1</custom>
        </group>
        <group>
                <name>some name 2</name>
                <custom>some custom text 2</custom>
        </group>
</root>
diff has the -I switch to ignore lines matching a reg-expression but running
Code:
diff input.xml template.xml -I custom
does not exclude the custom tags and they are overwritten.

The desired new template.xml whould be:
Code:
<root>
        <group>
                <name>some name 1</name>
                <custom>some custom text 1</custom>
                <missing>some other text 1 missing from template</missing>
        </group>
        <group>
                <name>some name 2</name>
                <custom>some custom text 2</custom>
                <missing>some other text 2 missing from template</missing>
        </group>
</root>
with "custom" tag untouched and the "missing" tag added.

Thanks
 
Old 05-30-2009, 04:03 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
An excerpt from info diff
Quote:
However, `-I' only ignores the insertion or deletion of lines that
contain the regular expression if every changed line in the hunk--every
insertion and every deletion--matches the regular expression. In other
words, for each nonignorable change, `diff' prints the complete set of
changes in its vicinity, including the ignorable ones.
This is your case: the difference in the vicinity of the ignorable lines, causes them to be printed out.
 
Old 05-31-2009, 02:55 AM   #3
nemobluesix
LQ Newbie
 
Registered: May 2008
Distribution: fedora
Posts: 13

Original Poster
Rep: Reputation: 0
Thumbs up conclusion

Thanks for your reply. It really helped me.
I inversed the "name" and "custom" tags so there were no changes in the vecinity of "custom" and the result is as expected. "Custom" is left untouched and "missing" is inserted.

I guess I should make a habbit reading info pages also not just the man .
Thanks again.
 
  


Reply

Tags
diff, patch



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
Please help ! Fedora Core 9 patch Dazuko patch-dazuko-linux-2.6.26.diff.gz R03L Fedora 3 10-22-2008 09:11 AM
Diff/Patch InJesus Programming 2 01-16-2007 10:56 PM
patch -p1 x.diff but no patch command!? pyenos Linux - Hardware 1 03-04-2005 03:10 PM
I have a patch (diff file). What now? Gurduloo Linux - Newbie 2 05-27-2003 02:20 PM
diff-patch mtb Linux - Software 1 03-23-2003 01:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:50 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
Open Source Consulting | Domain Registration