Removing ^M from file:
There are several ways to do it
(1) Using Vi editor
(1-1) To remove the ^M character, in ViM, write the following in the command mode and press :w to save the changes:
:set fileformat=unix
(1-2) Or, type this script in ViM, in the command mode and type :w to save the changes:
^V^M gives ^M character in the screen
:1,$s/^V^M//g
(2) Use sed:
$ sed 's/^M//g' filename > newfilename
(3) Use Dos2Unix
$ dos2unix filename newfilename
(4) Use col:
$ cat filename | col -b > newfilename
(5) Use 'tr' :
$tr -d '\r' < inputfile > outputfile