1753498 Members
4797 Online
108794 Solutions
New Discussion юеВ

Sed command-- Need help

 
SOLVED
Go to solution
Nagu SR
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
Dennis Handly
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.
Nagu SR
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
Suraj K Sankari
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
Dennis Handly
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
Nagu SR
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
rmueller58
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