Home » Infrastructure » Unix » Help needed on substitution in Unix (sed)
Help needed on substitution in Unix (sed) [message #357762] Thu, 06 November 2008 08:28 Go to next message
rak007
Messages: 107
Registered: October 2006
Location: Mumbai / Pune, India
Senior Member
I am using the following command in my UNIX code

sed "s/$FIND/$REPLACE/g" $IMP_RECORD_CTL > c.ctl


This command replaces all instances of $FIND with $REPLACE. These two variables contain some data and it operates on data contained in variable $IMP_RECORD_CTL and stores the result in file named c.ctl

Now after this i am using the following command

cat c.ctl | sed "s/POSITION FILLER/POSITION CONSTANT/g" > d.ctl


Here i am opening the file c.ctl (created above) and passing its contents to the sed command which will replace all instances of string "POSITION FILLER" with "POSITION CONSTANT" and put the contents in d.ctl

Now i want to effectively do both of these substitutions in the same file using a single command ( or something similar) . How can i achieve this ?

I mean i dont want to first substitute and put data in file c.ctl and then again substitute and put in d.ctl
Re: Help needed on substitution in Unix (sed) [message #357768 is a reply to message #357762] Thu, 06 November 2008 08:41 Go to previous messageGo to next message
Michel Cadot
Messages: 64120
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
sed -e "s/..." -e 's/...' myfile >myoutput

Google for sed.

Regards
Michel

[Updated on: Thu, 06 November 2008 08:41]

Report message to a moderator

Re: Help needed on substitution in Unix (sed) [message #357778 is a reply to message #357768] Thu, 06 November 2008 09:27 Go to previous messageGo to next message
rak007
Messages: 107
Registered: October 2006
Location: Mumbai / Pune, India
Senior Member
Thanks for the reply. I tried this but it goes in error.

sed -e "s/$FIND/$REPLACE/g" -e "s/POSITION FILLER/POSITION CONSTANT $i" $IMP_RECORD_CTL > c.ctl


Re: Help needed on substitution in Unix (sed) [message #357783 is a reply to message #357778] Thu, 06 November 2008 09:49 Go to previous message
rak007
Messages: 107
Registered: October 2006
Location: Mumbai / Pune, India
Senior Member
Hi Michel,
Sorry for my ignorance. Sad It is working fine. Thanks for the quick reply. Cool
Previous Topic: How to see status of instances (up / down / open)
Next Topic: Asking password when running the shell script to ftp the files
Goto Forum:
  


Current Time: Tue Dec 06 13:52:57 CST 2016

Total time taken to generate the page: 0.10120 seconds