I recently came across a duplicate set of files which contained similar information. In order to reduce clutter and clarify the information in one of the files, I used a the diff and merge command to compare and mesh to two file together so none of the data was lost.
So, if I have file 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>
and file 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 wanted to have an output similar to the following:
<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 following command allowed for the input from both original files and where differences occurred, it denoted it with the following characteristics:
- #ifndef VERSION1
- #else /* VERSION1 */
The command I used was as follows:
diff -DVERSION1 file1.xml file2.xml > merged.xml
This provided the addition and notation of the differences in both files so it makes comparison easier.