Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 

 

 

Changing hidden characters with UNIX vi


Don Burleson

 


There are times when you need to do a "change all" command in UNIX vi or sed, but the character is a "control character" that you cannot specify inside the change command:

 

Hello^M

There^M

 

The change command in vi

 

The above is what a MS-Word documents looks like when pasted into the vi buffer.  In vi, a "change all" command looks like this:

 

<esc>:.<$s/oldstring/newstring/g

 

This means:

 

<escape :>     Takes you to the vi command prompt

(dot)               Start on the current line

(comma)        Next parm

(dollar sign)   to end-of-file (EOF)

(s)                  Invoke the string editor (sed)

/old                The original string

/new               the new string

g                    global - Change all occurrences on a line

 

Removing the weird character

 

Now, what about removing the control character, ^M in our case?

 

We must "escape" the special character, using the <control> c key, like this, right before we enter the control m key::

 

:.,$s/<control c><control m>//g

 

When displayed in vi, it looks right:

 

:.,$s/^m//g

 

Change all in a set of files

 

The script below will allow you to invoke it using a file mask and issue a sed command on many file, all at the same time.  For example:

 

root> ./chg_all.sh *.sql

 

In this case we changed all files with a .sql suffix.  If we look at the script, we changed all strings ":Avg" to "Sum".  With Perl, some claim that this can be some in a single command:

 

find . -name "*.sql" -print | xargs perl -pi -e 's/Avg/Sum/g'

 

chg_all.sh

 

#!/bin/ksh

 

tmpdir=tmp.$$

 

mkdir $tmpdir.new

 

for f in $*

do

  sed -e 's/Avg/Sum/g' < $f > $tmpdir.new/$f

done

 

# Whoops

mkdir $tmpdir.old

mv $* $tmpdir.old/

# Whoops

 

cd $tmpdir.new

mv $* ../

 

cd ..

rmdir $tmpdir.new

 


 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster
 
 
 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2017

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

Remote Emergency Support provided by Conversational