Convert ^M to newline character in text files

Convert ^M to newline character in text files

If the ^M character is showing up in files while opening the file concerned, then follow these steps to convert it to a new line.
In vi use the following::%s/^M/\n/gor with perl on the command line:$ perl -pi.bak -e ’s/^M/\n/g’

NOTE: Be sure to create the ^M by typing ctrl V followed by ctrl M.

^M is ASCII 13 (Ctrl M), which is the carriage return.

Different operating systems use different symbols to set the end of a line/new line.
Unix uses newline (\n)
Mac uses carriage return (\r)
And Windows/DOS use both (\n\r)

To prevent the ^M from showing up in files, be sure to use the ASCII (text) mode when transfering text files.

 

Like this post ?

Share on your Social Networking Profile ( Facebook, Twitter & Google+ ) and get a flat 10% Recurring discount on our VPS Hosting and Dedicated Servers.

Email us the shared link at : sales@eukhost.com or speak to our live chat operator now, by clicking on the “Live Chat” Scroller on the left-hand side of this page and we will provide you with the discount Coupon right away!

Sharing

Leave your comment

Pin It on Pinterest

Shares
Share This

Please Share

Please be social and share this post with your friends!