If the file doesn't have the BOM at the start of the first line, the pattern won't match, and thus no change is made.
But as the the search is anchored with ^, this won't make any difference. This is a single logical command, and I did not include any line continuation commands: The following should work for you if you are on linux, mac, or if you have windows something like cygwin installed: $ xmllint -c14n File1.xml > 1.xml $ xmllint -c14n File2.xml > 2.xml $ diff 1.xml 2.xml