File gets truncated after using sed

May be this is a known issue. When I am using sed to change a string (globally) in multiple files, it is doing its job while truncating the file. So the xml files are losing some of the tags

Any work around? Appreciate your help guys......

Here is the code.....

#!/bin/sh

for files in *.xml; do

mv $files $files.old
sed 's/OLD_STRING/NEW_STRING/g' $files.old > $files
rm -f $files.old

done

can you show your input file before and after running the script ?

When I opened source file in "vi" for which string replacement is to be made I see a message "Incomplete last line" at the bottom. Any idea? Btb this is an xml file.