Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: How to remove ^M characters from a file  (Read 2764 times)

0 Members and 1 Guest are viewing this topic.

Haripriya H

  • Guest
How to remove ^M characters from a file
« on: January 11, 2014, 01:03:20 pm »
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

  • perl -p -i -e "s/\r\n/\n/g" filename.ext

2> Using Replace Command

  • replace "\r" "" -- filename.ext

3> Using vi editor

  • vi filename.ext


save and quit.