Compare two xml in Unix

Comparing xml’s is very easy one in unix using the simple diff command.

Diff command:
Diff command used to compare the differences of two files. Files may be any extension like xml or txt.

Syntax:
diff file1 file2

Eg:
diff 1.xml 2.xml —– compare this two xml and prints if any difference
diff 1.xml 2.xml > compare.txt —– compare this two xml and difference will be written in compare.txt

Some more…

1) diff 1.xml 2.xml (Normal compare)

2) diff -iw 1.xml 2.xml (Ignores spaces while comparing)

3) diff -y –suppress-common-lines 1.xml 2.xml (Two column compare)

-y => output in two columns
–suppress-common-lines => do not output common lines

4) diff -y –side-by-side –suppress-common-lines 1.xml 2.xml (two column compare side by side)

5) diff -y –side-by-side 1.xml 2.xml (two column compare side by side but whole file will come, which includes common lines as well)

6) diff -y –side-by-side –suppress-common-lines 1.xml 2.xml > compare.txt (Recommended one for comparing two xml)

Add if you know any other command/solutions to compare two xml’s in the comment section….

Leave a Reply