1838068 Members
4332 Online
110124 Solutions
New Discussion

Re: vi editor ^M char

 
Kenn Chen
Advisor

vi editor ^M char

I found ^M character at the end of each line in my file. How can i eliminate this funny char. Thanks.
Cyber Zen
12 REPLIES 12
Steven Sim Kok Leong
Honored Contributor

Re: vi editor ^M char

Hi,

# cat src.txt | col -b > dst.txt

or

# strings src.txt > dst.txt

Hope this helps. Regards.

Steven Sim Kok Leong
Steve Steel
Honored Contributor

Re: vi editor ^M char

Hi


If you copied the file from a PC then put it through dos2ux

in vi

:1,$s/cntrlVcntrlM//


cntrlV = Control+v
cntrlM = Control+m


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
John Waller
Esteemed Contributor

Re: vi editor ^M char

Hi, the ^M is a DOS CR/LF identifier. I guess the file has been modified on a DOS/Windows PC at some time. To remove from within vi try:

: 1,$s/^M//g

N.B For ^M press Ctrl+v then imediatltly press m

John Waller
Esteemed Contributor

Re: vi editor ^M char

Sorry Steve got it right, you need to keep the CTRL pressed i.e ctrl+v ctrl+m.

Silly thing was I actually tested before I sent the reply.
discoverer
Frequent Advisor

Re: vi editor ^M char

Inside vi, press:
!Gcol -bx

See what happen?

/discoverer
Listen, then discover, then succeed!
John Strang
Regular Advisor

Re: vi editor ^M char

Hello Idris,

You can do this within vi

:1,$ s/^V^M//

(NOTE You need the ^V then ^M
in order to enter the ^M charatcer)

This will erase the ^M character from each line.

HTH,

John

If you never make a mistake you'll never make anything.
Carlos Fernandez Riera
Honored Contributor

Re: vi editor ^M char

see man dos2ux.

If you get it from Win and ftp use ascii mode.

unsupported
Robin Wakefield
Honored Contributor

Re: vi editor ^M char

Hi,

...or you could do this in vi:

:%s/.$//

to remove the last char from every line.

Rgds, Robin.
Marc Dijkstra
Trusted Contributor

Re: vi editor ^M char

Hi there

Use the dos2ux command to strip out microsnot characters!

dos2ux > (outputfilename)

MND
"A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila"
Vincenzo Restuccia
Honored Contributor

Re: vi editor ^M char

in vi

:%s/cntrlV invio//g

with cntrlV you can insert ^M with invio.
Steve Steel
Honored Contributor

Re: vi editor ^M char

Hi

Another solution


Problem Description

I have transferred a file from another system, and I am editing the file
with the vi editor. The file has embedded carriage returns, which the
editor is displaying as ^M. How can I remove these extra characters?

Configuration Info

System 9000 HP-UX

Solution

Use the tr(1) command to remove these characters from the file.
First, quit the vi editor and then do the following:

Execute the tr command:

1. tr -d \\015 < inp_file > new_file

2. Inspect the file new_file with vi to check that the ^M's are gone.

steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Eric Buckner
Regular Advisor

Re: vi editor ^M char

Care should be taken when attempting to remove ^M from a file in vi. You really should anchor it to the end of line. I have really hosed up shar files w/o doing this when there was a ^M but it wasn't meant as a LF/CR.

%s/^V^M$//g

Should take care of your anchor.
Time is not a test of the truth.