LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   selective diff and patch (https://www.linuxquestions.org/questions/linux-newbie-8/selective-diff-and-patch-729290/)

nemobluesix 05-29-2009 06:34 AM

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

colucix 05-30-2009 04:03 PM

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.

nemobluesix 05-31-2009 02:55 AM

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.


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