Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The r (read) instruction in SED

Status
Not open for further replies.

canmike

Programmer
Nov 4, 2002
3
CA
Does anyone have an example of how to correctly use this instruction? I can write my changes to a file, put I've been unsuccessful in attempting to use this instruction.

Here is what I'd like to do. Through a KSH shell app, I need to substitute user names and directory locations in an Oracle init.ora file. I've got a canned init.ora file and I thought I could use the SED utility to modifiy this file. I thought if I could list the variables in a file, get SED to read the file, it could substitute the values in the init.ora file.

Something like '1,$ s/NEWSCHEMA/<name of new schema>/w init.ora'. Obviously '<name of new schema>' is the variable I'd like to change.

Can I read this value from a file and use SED to change the file?

I cannot get the syntax down for the read instruction:
1,$ r infile s/NEWSCHEMA/<name of new schema>/

 
Try :

sed -e s/oldschema/newschema/g initOLD.ora > initNEW.ora

or

using vi initOLD.ora

type :%s/oldschema/newschema/g
:wq initNEW.ora


EDC
 
Thanks for the answer, but:

The value newschema is a variable. I'm running all this inside a ksh shell script, so I can't, interactivity, enter any values. They're all read from a temporary file.

I tried substituting the newschema value in the SED command line using the standard KSH $, but SED can't understand the argument placeholder.

This all has to run through a KSH shell *.sh file.
 
just to catch the idea:

#!/usr/bin/ksh
INFILE=$1
OUTFILE=`basename $INFILE .ora`.new

echo &quot;Enter the old schema: \c&quot;
read OLD
echo &quot;Enter the new schema: \c&quot;
read NEW

sed -e s/$OLD/$NEW/g $INFILE > $OUTFILE

EDC
 
YAHOO!

Thanks you so much. It works. Call it three time, the number of variables, and it substitutes all variables.

I'm not familiar with the -e argument?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top