How to remove ^M characters from a file

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

[email protected][#] perl -p -i -e "s/\r\n/\n/g" filename.ext

2> Using Replace Command

[email protected][#] replace "\r" "" -- filename.ext

3> Using vi editor

[email protected][#] vi filename.ext

save and quit.

That’s all.