Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1509
  • Last Modified:

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
0
blx
Asked:
blx
1 Solution
 
liddlerCommented:
You should be able to see the ^M character in vi..
To delete them try: sed -e "s/^M//" scrpit > newscript
The newscript will then have the ^M's removed

Then try running newscript (you may have to chmod +x it)

HTH
0
 
HamdyHassanCommented:
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

           
0
 
tfewsterCommented:
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
nebekerCommented:
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).
0
 
liddlerCommented:
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
0
 
tfewsterCommented:
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 :-)
0
 
liddlerCommented:
I hate to give myself points - unless I'm absolutely sure
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now