Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Sed command-- Need help

 
SOLVED
Go to solution
Highlighted
Frequent Advisor

Sed command-- Need help

Hi,

I have a quite few no. of scripts in a directory /Scripts. In every Script in the DIR, I want to replace the text OS with Cargos.

One of the sample script is ....

if [ $ERR -gt 0 ]
then
#Object failed
/opt/OV/bin/OpC/opcmsg application=Monitor severity=critical object=OS msg
_text="$0: Object failed" msg_grp=GEC node=test.sample.com
fi
else
# Second Object failed
/opt/OV/bin/OpC/opcmsg application=Monitor severity=critical object=OS msg_t
ext="$0: Second Object failed" msg_grp=GEC node=test.sample.com
fi

I intent to change object=OS to object=Cargos



After going through man pages of sed, I issued command,

sed 's/OS/Corgos/g' sample.sh

still Object remains OS.


Any Idea, where I'm doing mistake?

Regards,
Nagu
6 REPLIES 6
Highlighted
Acclaimed Contributor

Re: Sed command-- Need help

The output of sed is to stdout so you need:
sed 's/OS/Corgos/g' sample.sh > sample.sh.new
Then move it back.
Highlighted
Frequent Advisor

Re: Sed command-- Need help

Thanks.

Is there any way so that I can avoild moving files??

May not be with sed, if it doesnt support
Highlighted
Honored Contributor

Re: Sed command-- Need help

Hi,
You can open your file into vi
vi sample.sh

press Esc, then press : type below string

:1,$s/OS/Corgos/gp press enter

it will change your OS string into Corgos

Suraj
Highlighted
Acclaimed Contributor
Solution

Re: Sed command-- Need help

>Is there any way so that I can avoid moving files?

You can use ex(1) instead. See this other thread:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1322777

ex <%s/OS/Corgos/g
wq
EOF
Highlighted
Frequent Advisor

Re: Sed command-- Need help

Thanks Dennis,

Your suggestion helped me to meet my requirement of changing the stuff in over 100+ scripts.

Thanks a lot

Regards,

Nagu
Valued Contributor

Re: Sed command-- Need help

if you want to edit in place, use a perl line.

perl -pi -e 's/OS/Corgos/g' sample.sh

with sed you have to re-direct output to a 2nd file.. > 2ndfilename.ext