Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

^M

Status
Not open for further replies.

BIS

Technical User
Jun 1, 2001
1,893
0
36
NL
How do I type ^M in vi? or on the command line?

For example I want to type

cat file | tr -d '^M' > new.file

but I can't figure out how to type this.
 
control-v and control-m in tandem create the ^M character.
Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
once you know its easy isn't it :)

thanks
 
How about cat file.name | tr -d '\015' > newfile.name ? This strips the ^M

 
good solutions all, however i am running into a problem.

This is a sample text file:

blablablabla
blablablabla

When viewed in DOS it looks like this:

blablablabla{space}
blablablabla

and in vi:
blablablabla^M
blablablabla

If I do a cat file | tr -d '^M' > new file

It looks good in vi, but in DOS looks like this:

blablablabla{space and a small square}blablablabla

I want to strip the last space when viewed in DOS, so that the end result is:

blablablabla
blablablabla

Any ideas?
 
Line terminator sequences:
[tt]
UNIX: \n Newline
Windows/DOS: \r\n Carriage-return, Newline
[/tt]
Removing the \r from your file to make it UNIX friendly makes it DOS-unfriendly :-(. Some Windows based editors are clever enough to try both syles of line terminator.

Cheers, Neil :)
 
well it is solaris, and I do have the unix2dos utility.

Here is the problem,

if I do a unix2dos file > file

the file ends up empty - no good. so I do

unix2dos file > tmp.file
rm file
cp tmp.file file
rm tmp.file

but somehow in this process I end up getting a space after the first line....
 
BIS - don't redirect your output. Unix2dos allows for infile outfile without redirection. Cheers.
 
thanks.

but i still have that extra space at the end of the first line (in notepad I can move the cursor one step to the right). hmmmm

is a space character represented by something, like the carriage return and new-line as toolkit mentioned above?
 
Isn't that normal behaviour for notepad? - it's not like vi in that it allows you to add spaces regardless of mode. Where does the cursor end up when you put it at the beginning of the line and press the end key? (there's a joke there somewhere....). Cheers.
 
Could be I am staring myself blind at this sentence, but I have still not found the joke... :-(

If I in notepad press the backspace key, the file has changed. How do I get rid of that bleeding extra space..

I will try to fiddle around a bit.
 
BIS, hope your fiddling worked. My 'joke' if you can call it such) comes from a help desk call (possibly apocyphal, but who knows) ie:

Help Desk: 'What happens when you press the End key?'

User: Which end of the keyboard?

Cheers.
 
ok, after a nice rest you tend to see the obvious...

tr -d ' '

solved it. how stupid of me. many thanks for your input and help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top