?
Solved

Control Characters in vi

Posted on 2003-03-05
8
Medium Priority
?
1,508 Views
Last Modified: 2013-12-20
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
Comment
Question by:blx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 18

Accepted Solution

by:
liddler earned 200 total points
ID: 8071061
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
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8071214
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
 
LVL 21

Expert Comment

by:tfewster
ID: 8074141
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
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
LVL 5

Expert Comment

by:nebeker
ID: 8093932
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
 
LVL 18

Expert Comment

by:liddler
ID: 9827223
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
 
LVL 21

Expert Comment

by:tfewster
ID: 9828134
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
 
LVL 18

Expert Comment

by:liddler
ID: 9830389
I hate to give myself points - unless I'm absolutely sure
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
In this post we will learn different types of Android Layout and some basics of an Android App.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question