This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

^M thing at the end of every line

Help for those learning Tcl or writing their own scripts.
Post Reply
e
emokid
Voice
Posts: 22
Joined: Fri Dec 07, 2007 5:31 pm

^M thing at the end of every line

Post by emokid »

For some reason, there is a ^M character at the end of every line in a script. How can I get rid of all of them? (It's not 2 separate characters, ^M seems to be just one if I try to move my cursor to it, or press backspace it deletes ^M at the same time.)
User avatar
YooHoo
Owner
Posts: 939
Joined: Thu Feb 13, 2003 10:07 pm
Location: Redwood Coast

Post by YooHoo »

Sometimes certain characters(for eg.,^M characters)are placed in a file during a DOS to UNIX conversion. To modify these files with a lot of ^M symbol at the end of every line, using the vi editor, use the following command:

Code: Select all

:%s/^M//g
(To get the ^M hold the control key, press V then M (Both while holding the control key) and the ^M will appear.)
This command will find all occurances and replace them with nothing.
Here, the :%s is a basic search and replace command in vi. It tells vi to replace the regular expression between the first and second slashes (^M) with the text between the second and third slashes (nothing in this case). The g at the end directs vi to search and replace globally (all occurrences).
e
emokid
Voice
Posts: 22
Joined: Fri Dec 07, 2007 5:31 pm

Post by emokid »

Thanks, that did the trick!

But do you know why the ^M character appears during DOS to UNIX conversion? What's this symbol called and the story behind it?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

emokid wrote:Thanks, that did the trick!

But do you know why the ^M character appears during DOS to UNIX conversion? What's this symbol called and the story behind it?
ascii 13, hex 0d ; it's a carriage return marker...

A quick google pulled up this, probably helpful for you to tell other control-sets and their meanings.
Post Reply