|
Last updated: 07/03/2009
Oh, the dreaded ^M - these usually occur when uploading files from a windows system, using ascii mode. Some Windows editors may add the character to the end of each line as well during editing.
Sometimes, it's hard to even find them. One pretty foolproof way on a Linux / Unix system is to use cat:
cat -e [filename]
This will show you lines with a $ at the end, and ^M's should show up, if they are there. Here are a few options to remove them:
Method 1:
In the vi editor, do the following:
:.,$s/(ctrl-v)(ctrl-m)//g (enter)
After typing the (ctrl-v)(ctrl-m) combination, you should see a "^M" in the line (note, the ^M is NOT just a '^' and an 'M', it's a special control character. If you try to reproduce it without the control sequence I describe here, you'll really mess up your file.
By the way, if you do screw something up, just type:
:q!
which will exit the editor without saving, and you can start fresh and try again.
Method 2: Using sed
Method 3:
If your system has the 'dos2unix' utility, you can do this:
dos2unix [filename]
This has the advantage of replacing the original file, so you don't need to move anything after running this command.
|