1863009 Members
1608 Online
110446 Solutions
New Discussion

Re: control characters

 
SOLVED
Go to solution
Prashant Zanwar_4
Respected Contributor

control characters

Hi,
I am formating a scriptfile created from script command as it is having few unwanted charcters like ^M, ^H ...I just dont want these charcters. Can I do this using vi..Please suggest.
Thanks
Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
4 REPLIES 4
Rick Garland
Honored Contributor

Re: control characters

You can cat the file and pipe through the `tr` utility to be gone of the ^M

cat | tr -d '/015' >

The /015 is octal for the ^M character.

Another option is the dos2unix command.

Sundar_7
Honored Contributor
Solution

Re: control characters

You are better off doing this with sed than vi

sed -e 's/^M//g' -e 's/^H//g' inputfile > output

To enter ^M and ^H in the command line, try this

and then = ^M
and then = ^H
Learn What to do ,How to do and more importantly When to do ?
Andrew Merritt_2
Honored Contributor

Re: control characters

Doing it automatically is best without vi, as the others have suggested.

If you do want to remove the characters while you are editing the file in vi, then enter:

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

Where ^V is control-V and ^M is control-M; this will remove all the ^M chars. Control-V escapes the next character and lets you enter it without it having its normal effect. The ^V won't display in the command on the screen.

To remove all the ^H chars:

:1,$ s/^V^H//g

(the 'g' is needed as there could be more than one ^H on a line)

Andrew
bhavin asokan
Honored Contributor

Re: control characters

dear prashant,

try this

cat filename |col -bx >filename1

this will remove the junk characters.
regds,