Sometimes when you upload or FTP files from a Windows system to a UNIX box you will see ^M at the end of each line. ^M is the UNIX equivalent of DOS line break. Not only does it not look pretty, this extra character may break all sorts of scripts that you try to run on your file. So how do you remove ^M? Here are two ways to get rid or ^M (Ctrl-M) from your files.
Option 1.Use dos2unix utility. The easiest way is to use dos2unix utility.
dos2unix originalfile convertedfile.
You can run man dos2unix to learn about all the options.
Option 2. If you do not have dos2unix utility the next best option is to edit the file in VI. Open the file in VI editor and do a global search and replace.
:%s/(ctrl+V)(ctrl+M)//g and hit enter.
Be aware that ^M is not just a ^ followed by a M. You will have to press CTRL and V to get ^ and then CRTL and M to get the M.
After replacing ^M do :wq or ZZ to save and exit the VI editor.
Enjoy.
Popularity: 4% [?]
If you enjoyed this post, make sure you subscribe to my RSS feed!Related posts:
- How to remove (delete) Eclipse workspace from the dropdown list.
- Share your files with DropBox
- How to add external jar files to Maven project POM
- Compress JavaScript and CSS files to optimize website speed.
- How to customize More tag in WordPress






You saved me a lot of headache. Thanks for the useful tip.