Link to home
Start Free TrialLog in
Avatar of blx
blx

asked on

Control Characters in vi

I want to be able to view control characters in vi. When I run a script created in vi, I get the following message "Bad Interpreter". I believe that it is possible to have the ^M character in the script, (however I can't view it). I want to be able to view it and then delete all instances of it.
Your help is really appreciated.

Blx
ASKER CERTIFIED SOLUTION
Avatar of liddler
liddler
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HamdyHassan
HamdyHassan

To view them from vi, do the following

vi file.txt
<ESC>
:
/<CTRL>v<CTRL>m            

this will jump to the first ^M at the file, to find the next just press /


To remove them from vi do the following
vi file.txt
<ESC>
:1,$s/<CTRL>v<CTRL>m//g


To remove them from command prompt , you can use "sed" as liddler  mentioned but again to type ^M, you need to press
<CTRL>v<CTRL>m

           
To view other control characters in vi, (e.g. tab, space at end of line), type
: set list

However, the "Bad interpreter" sounds like your hashbang line (e.g. #!/usr/bin/ksh) is specifying an invalid shell. If you are still having problems, please post the hashbang line & the output of `uname -a` here.
And there's always the dos2unix command:

dos2unix the_filename

It's a little simpler than typing a sed command  :)  Note that this program may not be installed on your system.  If not, check for the unix2dos program (some versions will automatically convert the file, and others require a simple flag to convert from dos -> unix).
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by tfewster

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

liddler
EE Cleanup Volunteer
Thanks liddler, but the chances are that the hashbang line had a ^M at the end of it, and I believe that would give the "bad interpreter" error - So your first comment would have fixed the problem and you earned the points :-)
I hate to give myself points - unless I'm absolutely sure