Many time it happens that when you open a file in vi editor you see a ^M character at some places in a file and a ^M character is nothing but a carriage return character in Linux.
You normally found those characters when you transfer a file from a windows machine to a Linux box.
The ^M character [Carriage Return] can easily be removed by following one of the below method ::
1 > Using Perl
root@server[#] perl -p -i -e "s/\r\n/\n/g" filename.ext
2> Using Replace Command
root@server[#] replace "\r" "" -- filename.ext
3> Using vi editor
root@server[#] vi filename.ext
save and quit.