Operating System - HP-UX
1820256 Members
3171 Online
109622 Solutions
New Discussion юеВ

how to search and replace ^M in vi?

 
SOLVED
Go to solution
faust2004
Regular Advisor

how to search and replace ^M in vi?

Hi,experts,

I have file in hp unix box , for comvenience, I ftp to window, edit it , and ftp it back to unixbox, i find ^M appear in the end of each line, how delete it in vi?

another question : if the vi said the line is too long for edit and does not display for edit, what to do?

Thanks
Sunny

4 REPLIES 4
Michael Tully
Honored Contributor
Solution

Re: how to search and replace ^M in vi?

Hi Sunny,

There are special tools for converting files
from Unix to DOS and back again. They
are 'dos2ux' and 'ux2dos'

There is a man page detailing both commands.

Using these two utilities, there is no need
to try and edit them using vi.

HTH
~Michael~
Anyone for a Mutiny ?
Scott Van Kalken
Esteemed Contributor

Re: how to search and replace ^M in vi?

within vi you could use


:%s/^M//g


note that the ^M is formed by pressing
Steven Sim Kok Leong
Honored Contributor

Re: how to search and replace ^M in vi?

Hi,

Without using vi, you can also do:

# cat dosfile | col -b > unixfile

OR:

# strings dosfile > unixfile

Hope this helps. Regards.

Steven Sim Kok Leong
Deepak Extross
Honored Contributor

Re: how to search and replace ^M in vi?

You files have this ^M at the end of each line because you are FTP'ing the file from Unix to Dos in Binary mode.
Switch to Ascii mode (type 'asc' at the ftp prompt) before sending text files, and you won't have this problem.

Hope this helps.