Operating System - HP-UX
1832616 Members
3711 Online
110043 Solutions
New Discussion

in vi how can I delete the ^M

 
Martin_171
Occasional Advisor

in vi how can I delete the ^M

so many ^M in the file ,how can I delete them?
13 REPLIES 13
V.Tamilvanan
Honored Contributor

Re: in vi how can I delete the ^M

Hi,

To delete all the ^M. You need to the below.

:s///g
V.Tamilvanan
Honored Contributor

Re: in vi how can I delete the ^M

Hi,

As the ^M is a special character you need to type Ctrl key and V key together and Ctrl key and M key together.
Martin_171
Occasional Advisor

Re: in vi how can I delete the ^M

I used your way but the ^M still there.
Michael Tully
Honored Contributor

Re: in vi how can I delete the ^M

There is a specific program to do this.

$ dos2ux file1

See the man page for details, Using 'sed' will also work.
Anyone for a Mutiny ?
Mark Grant
Honored Contributor

Re: in vi how can I delete the ^M

You could try something like this

perl -pne 's/chr(13)//;' filename > newfile
Never preceed any demonstration with anything more predictive than "watch this"
Jan Sladky
Trusted Contributor

Re: in vi how can I delete the ^M

I simply use hp-ux utility dos2ux, type this:

# dos2ux file_with_M | tee file_without_M

reverse is ux2dos ;-)

br Jan
GSM, Intelligent Networks, UNIX
Joseph Loo
Honored Contributor

Re: in vi how can I delete the ^M

hi,

either use the command:
# dos2ux >

or
# vi
:1,s$/^M//
where ^M is holding down ctrl and press the key v and then m

regards.
what you do not see does not mean you should not believe
Joseph Loo
Honored Contributor

Re: in vi how can I delete the ^M

sorry, it should be
:1,$s/^M//

regards.
what you do not see does not mean you should not believe
generic_1
Respected Contributor

Re: in vi how can I delete the ^M

To remove the ^M characters with vi type this
:%s/^V^M//g

It comes out like this:

:%s/^M//g

This should fix your file.

Re: in vi how can I delete the ^M

try this command. it works.

:g/CTRL-VM/s///g
Johan Brusche
Honored Contributor

Re: in vi how can I delete the ^M


Yet another way:

tr -d '\r' < file-with-cr > file-nocr

JB.

_JB_
Fred Ruffet
Honored Contributor

Re: in vi how can I delete the ^M

If you don't want to deal with typing ^M, and as long as you have a ^M at each end of line, just issue
:1,$s/.$//
(deletion off all last characters)

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Mike Stroyan
Honored Contributor

Re: in vi how can I delete the ^M

Once you are in vi you can use the following command to pipe the file through dos2ux.
:%!dos2ux

I find it very handy to pipe files or line ranges through various commands from inside of vi. The following on fixes indentation of C code.

:%!cb -s | expand -4 | unexpand

This entry in ~/.exrc makes vi fix line wrap and indentation for the current paragraph when I press function key one.
map #1 {!}exec adjust