Operating System - HP-UX
1821539 Members
2154 Online
109633 Solutions
New Discussion юеВ

Re: How to change chars (CTRL+M)

 
SOLVED
Go to solution
Carme Torca
Super Advisor

How to change chars (CTRL+M)

Hi,

I have a file whith caracters wrong:
SELECT * FROM `M
SELECT * FROM `M
and I want to change all `M to nothing. Is it possible?, with vi, I can't change it, (its CTRL+M), Is there another way to do this?

Thanks very much.
Carmen.
Users are not too bad ;-)
8 REPLIES 8
Pete Randall
Outstanding Contributor
Solution

Re: How to change chars (CTRL+M)

Would running the file through dos2ux help, perhaps?


Pete

Pete
A. Clay Stephenson
Acclaimed Contributor

Re: How to change chars (CTRL+M)

dos2ux < oldfile > newfile.

Man dos2ux for details. ux2dos does the reverse operation.
If it ain't broke, I can fix that.
Ian Killer_1
Regular Advisor

Re: How to change chars (CTRL+M)

Hi Carmen...

The control M appears in DOS text files when transfered to unix. You'll find a very old utility on every HP-UX system called dos2ux or ux2dos if you want to convert back. This should remove all the ^M's for you.

Cheers..

Ian
Where ever the gypsies rome.
Sridhar Bhaskarla
Honored Contributor

Re: How to change chars (CTRL+M)

Hi Carmen,

You can do it with vi. Do the following

vi

:%s/^M//g

You can get ^M by pressing Control-V and Control-M together.

Looks like you have a file copied from dos. The other way of getting rid of these characters is to use "dos2ux". 'dos2ux your_file > newfile'.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Francisco J. Soler
Honored Contributor

Re: How to change chars (CTRL+M)

Hi, Carmen,

In vi it is possible do the change, use the following substitution:

:%s/^V^M//

Where ^V is CTRL+V and ^M is CTRL+M

Cheers.
Frank.
Linux?. Yes, of course.
Hai Nguyen_1
Honored Contributor

Re: How to change chars (CTRL+M)

Carmen,

You can use vi to get rid of them in command mode:

:1,$ s/ctrl+v ctrl+m//

Note: there is no space between the two "ctrl+v" and "ctrl+m". I just wanted to make the command sequence visible.

Hai
Carme Torca
Super Advisor

Re: How to change chars (CTRL+M)

Perfect!
Thanks a lot of!!!
Users are not too bad ;-)
Louis A. Lopez
Occasional Advisor

Re: How to change chars (CTRL+M)

Carmen,

We know that CTRL-M is octal 015. So to remove it from the file try this:

cat file1 | tr -d '\015' > file2

Now file2 has no CTRL_M characters and you still have the original file1 for reference.

Hope it works,
Lucky Lou :-)