I have read about diff and patch but I can't figure out how to apply what I need. I guess its pretty simple, so to show my problem take these two files:
a.xml
<resources>
<color name="same_in_b">#AAABBB</color>
<color name="not_in_b">#AAAAAA</color>
<color name="in_b_but_different_val">#AAAAAA</color>
<color name="not_in_b_too">#AAAAAA</color>
</resources>
b.xml
<resources>
<color name="same_in_b">#AAABBB</color>
<color name="in_b_but_different_val">#BBBBBB</color>
<color name="not_in_a">#AAAAAA</color>
</resources>
I want to have an output, which looks like this (order doesn't matter):
<resources>
<color name="same_in_b">#AAABBB</color>
<color name="not_in_b">#AAAAAA</color>
<color name="in_b_but_different_val">#BBBBBB</color>
<color name="not_in_b_too">#AAAAAA</color>
<color name="not_in_a">#AAAAAA</color>
</resources>
The merge should contain all lines along this simple rules:
- any line which is only in one of the files
- if a line has the same name tag but a different value, take the value from the second
I want to apply this task inside a bash script, so it must not nessesarily need to get done with diff and patch, if another programm is a better fit
diff
can tell you which lines are in one file but not the other, but only on the granularity of entire lines.patch
is only suitable for making the same changes to a similar file (perhaps a different version of the same file, or an entirely different file where however the line numbers and surrounding lines for each change are identical to your original file). So no, they are not particularly suitable for this task. You might want to have a look atwdiff
but the solution probably requires a custom script. Since your data looks like XML, you might want to look for some XSL tool.