Search and replace

Hi All,

Suppose I have a file "a.doc"

It's contents are :

mos44.0 )

      .....
      ......
      .....


  export TKTS_RELEASE=tkts44.0b7
      ......
      .......

Now , I need to first search for the pattern "mos44.0 )" and then TKTS_RELEASE will be some 30 lines below(not 30 always)...

I need to go there and then modify the value of TKTS_RELEASE variable from tkts44.0b7 to tkts44.0b10.

For modifying the contents I can use sed command ...But how do I determine where the changes shud be done...The place where I change shud satisfy two conditions ...1) "mos44.0 )" and then some lines below..TKTS_RELEASE variable..

Kindly advice...Thanking in advance....

You may try this:

grep -q "mos44.0" file_name && sed 's/tkts44.0b7/tkts44.0b10/' file_name

Can you show a bit more of this file please? Is "mos44.0 )" a kind of label that marks the start of a section? Is there anything else marking a kind of end of that section ie. when replacement should be stopped/not done?

This should replace the first match of "tkts44.0b7" after "mos44.0"

awk '
/mos44.0/{f=1}
/TKTS_RELEASE=/ && f {sub("tkts44.0b7","tkts44.0b10");f=0}
{print}' file > newfile

Regards

Franklin,
Thanks a lot for your response...

I ran the command but I get this error

awk '/mos44.0/{f=1}/TKTS_RELEASE=/ && f {sub("tkts44.0b7",tkts44.0b10");f=0} {print}' bmp.config > bmp1.config
awk: syntax error near line 1
awk: bailing out near line 1

zaxxon,
FInd the file

6194 mos44.0 )

6195 prepath PATH /scme/lbin /opt/SUNWspro/bin /opt/nmake3.1.
2/bin /usr/ccs/bin/usr/add-on/unison/bin
6196 addpath PATH /opt/quantify
6197 addpath MANPATH /opt/quantify/man /opt/purify/man

6221 export DSS_RELEASE=dss11.0b1
6222 export MOS_RELEASE=mos44.0b1
6223 export TSTS_RELEASE=tsts41.0b1
6224 export COM_RELEASE=com33.0b1
6225 export TKTS_RELEASE=tkts44.0b7
6226 export CCPLITE_RELEASE=ccplite1.0
6227 export TKES_RELEASE=tkes11.0b8

mos44.0 ) (mos44.0 followed by a closing bracket ) in line 6194 of the file

then TKTS_RELEASE variable in line 6225...

Need to modify this TKTS_RELAESE variable to tkts44.0b10.

TKTS_RELEASE variable will be at several places ..but I need to modify this variable only after some lines from mos44.0.

Use nawk or /usr/xpg4/bin/awk on Solaris.

Regards

mahendrt,

grep "mos44.0" file_name && sed 's/tkts44.0b7/tkts44.0b10/' file_name seems to work..but it is modifying TKTS_RELEASE variable to tkts44.0b10 everywhere in the file where it is tkts44.0b7 which is undesirable...What can be done?

Sandhya

Lose the grep and just use sed.

sed '/mos44\.0)/,/TKTS_RELEASE/s/TKTS_RELEASE=tkts44\.0b7/TKTS_RELEASE=tkts44.0b10/' file

This will replace the first occurrence of TKTS_RELEASE=tkts44.0b7 after each occurrence of mos44.0)

There are differences between sed dialects so you may or may not need to backslash the closing parenthesis after mos44.0. Or just take it out if there are no other occurrences of this text in the file in cumbersome places.