Operating System - HP-UX
1834512 Members
2397 Online
110068 Solutions
New Discussion

vi editor ^M char ... pt 2.. My wired run in ..

 
SOLVED
Go to solution
someone_4
Honored Contributor

vi editor ^M char ... pt 2.. My wired run in ..

This post is related someone to
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xf6f45e938a10d6118ff40090279cd0f9,00.html

But my issue that I have run in to was with my appache.conf file. Now I know this has never been edited in windows. Or anything but When I vi the file I get the ^M at the end of everything.But when I more the file it looks good. .. weird. Well I never messed with it and it never messed anything up. So I just left it alone. But I have always wondered why it would show on the vi but not on the more. Doesnt show with cat either. Only vi.

richard
6 REPLIES 6
Steve Steel
Honored Contributor
Solution

Re: vi editor ^M char ... pt 2.. My wired run in ..

Hi


The vi makes a non printable character visible and what you have is an extra carriage return because the file is in dos format and cr is implicit in UX.

More will ignore it as will cat


To remove

A)dos2ux

B)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.

C)vi file

use
:1,$s/cntrlvcntrlm//g

where cntrlv = control+v
cntrlm = control+m

Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
harry d brown jr
Honored Contributor

Re: vi editor ^M char ... pt 2.. My wired run in ..

Richard,

If you are already in vi when you notice these "extra"'s, you can remove them by doing this:

:s/^v^m//g999999

Where ^v is control v, and ^m is control m.

or as already stated outside of vi: dos2unix

live free or die
harry
Live Free or Die
Sanjay_6
Honored Contributor

Re: vi editor ^M char ... pt 2.. My wired run in ..

Hi Richard,

"cat" command suppresses the control characters and uses the terminal settings to interpret the control characters. If you want to view the control charcater use the -v option with cat command. Without -v option the terminal will display the control character with cat if the terminal is set to display control charcacters instead of interpreting them.

cat -v file_name

hope this helps.

Regds
Carlos Fernandez Riera
Honored Contributor

Re: vi editor ^M char ... pt 2.. My wired run in ..

cat and more show it... but you cant see it because it is intrepreted correctly by your terminal or emulator.

^M is a control char .

This is vi interpretes and change its aparience.

unsupported
A. Clay Stephenson
Acclaimed Contributor

Re: vi editor ^M char ... pt 2.. My wired run in ..

Hi Richard:

This is a DOS/Windows textfile where the convention the convention is that every line ends with a CRLR Pair. In UNIX textfiles, each line simply ends in an LF.
In CR's are ASCII 13's (decimal) or Ctrl-M's; LF's are ASCII 10's (decimal) or Ctrl-J's.

In most cases, your output device is set yo ignore CR's and that is why you don't see them with cat. There are utilities to remove the CR's. Man dos2ux for details. Man stty for details on why you don't see CR's.

Regards, Clay

If it ain't broke, I can fix that.
someone_4
Honored Contributor

Re: vi editor ^M char ... pt 2.. My wired run in ..

So someone must have jacked with this file in windows. And then ftp'd it back to my server. hmmmm .. I dont think it was me because I rememeber a long time ago one day I was working on the appache.conf and it was like that.I never did mess with because it didnt seem to mess anything up. But now I do understand why I cant see them with cat and more. And how they got there. Goood stuff!!

10s for everyone..

Richard