Operating System - HP-UX
1755150 Members
5331 Online
108830 Solutions
New Discussion юеВ

Re: Getting rid of metacharacters (^M) with VI or any other way?

 
SOLVED
Go to solution
MAD_2
Super Advisor

Getting rid of metacharacters (^M) with VI or any other way?

I have some scripts that were created and placed into a tar file. When I untar the file into a server, the metacharacter (^M) comes up at the end of every line in each script. The scripts are not working and I think is due to this character at the end of every line.

Is there a simple way I can get rid of this metacharacter? There are a few scripts that work together and right now they all have that character at the end.

I was able to run a single script by manually deleting the character at the end of each line, but the entire program will not work because many of these tie together,this unless all other files are also cleaned up.

Why did this happen?

Thanks,
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
7 REPLIES 7
Uday_S_Ankolekar
Honored Contributor
Solution

Re: Getting rid of metacharacters (^M) with VI or any other way?

Hi,

Try this

vi the file

:%s/.$// To delete Last charaecter from every line

Also You can try this


%s/^V^M$//g

-Goodluck.

-USA..
Good Luck..
MAD_2
Super Advisor

Re: Getting rid of metacharacters (^M) with VI or any other way?

Found a good answer. The Internet is amazing, I did a quick search using a favorite search engine and got a result. However, I would still like to know how I can use something like sed or awk to do the replacement in a series of files. This is what I found:

Using vi, type :
and then -->

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

This will replace the metachacter ^M

Thanks,
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
SHABU KHAN
Trusted Contributor

Re: Getting rid of metacharacters (^M) with VI or any other way?

Hi,

There are many ways by which you could delete the unprintable/control characters ...

Here are a couple of ways you could do this:

strings badfilename > goodfilename

dos2unix badfilename > goodfilename

Hope this helps !

Thanks,
Shabu
Heiner E. Lennackers
Respected Contributor

Re: Getting rid of metacharacters (^M) with VI or any other way?

Hi,

the correct command under hp-ux is "dos2ux", but the usage is ok.

Heiner
if this makes any sense to you, you have a BIG problem
MAD_2
Super Advisor

Re: Getting rid of metacharacters (^M) with VI or any other way?

Guess I should had mentioned I was using the command on a Unixware 2.1.3. The strings command worked perfectly.

Thanks everyone...
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
Holger Knoppik
Valued Contributor

Re: Getting rid of metacharacters (^M) with VI or any other way?

Hi !
Try with sed:
sed 's/.$//g' file > newfile

HTH
RGDS, Holger
Live long and prosper!
Niraj Kumar Verma
Trusted Contributor

Re: Getting rid of metacharacters (^M) with VI or any other way?

you can also use the following

# cat |col -b >

e.g,

# cat file1 |col -b >file.new

--Niraj
Niraj.Verma@philips.com