To change Specific Lines in An XML file

hi Guys,

this is my requirement, there is a huge xml file of this i have to change 3 lines with out opening the file

 /users/oracle > cat lnxdb-pts-454.xml|egrep "s_virtual|s_cluster|s_dlsnstatus"
      <cluster_port oa_var="s_clusterServicePort">9998</cluster_port>
      <host oa_var="s_virtual_hostname">lnxdb-pts-454</host>
      <private_address oa_var="s_clusterInterConnects">lnxdb-pts-454-rac</private_address>
         <oa_process_status oa_var="s_dlsnstatus">enabled</oa_process_status>
/users/oracle > 

#### Required Output

 /users/oracle > cat lnxdb-pts-454.xml|egrep "s_virtual|s_cluster|s_dlsnstatus"
      <cluster_port oa_var="s_clusterServicePort">9999</cluster_port>
      <host oa_var="s_virtual_hostname">lnxdb-pts-454-vip</host>
      <private_address oa_var="s_clusterInterConnects">lnxdb-pts-454</private_address>
         <oa_process_status oa_var="s_dlsnstatus">disabled</oa_process_status>
/users/oracle > 

I tried with using Sed, started with one parameter "s_vitrual_hostname" ...but iam not able to make the changes without opening the file..

I just have to run one shell script & it should take care of the file, ofcourse the script would include the above parameters :slight_smile:

can anyone help me with this..i have to do similar modifications on 20 hosts like this, thought a small shell script would fix it

thanks in Advance
sai

sed  "s/s_virtual_hostname\">lnxdb-pts-[0-9]*/&-vip/"  <filename>

if you have GNU sed you can use

sed -i "s/s_virtual_hostname\">lnxdb-pts-[0-9]*/&-vip/"  <filename>
1 Like

thanks gowtham

sed -i "s/s_virtual_hostname\">lnxdb-pts-[0-9]*/&-vip/"  <filename>

so, from the above command, i Understood that you are searching this particular line in the file using sed

<host oa_var="s_virtual_hostname">lnxdb-pts-454</host>

so does * indicate the later part of the line which means "</host> ?
and
in the second argument of sed how does "&" going to work?

========== My second Requirement is =========

<dbsharedpool oa_var="s_dbsharedpool_size">300000000</dbsharedpool>
         <dbutilfiledir oa_var="s_db_util_filedir" osd="unix">/apps/orarpt/TS3CTS/utl</dbutilfiledir>

Output should be as follows

the New line should be added from outside ("NOROLLBACK" line) and should exactly come in the middle of the above two lines........

<dbsharedpool oa_var="s_dbsharedpool_size">300000000</dbsharedpool>
         <dbrollbacksegs oa_var="s_db_rollback_segs">NOROLLBACK</dbrollbacksegs>
         <dbutilfiledir oa_var="s_db_util_filedir" osd="unix">/apps/orarpt/TS3CTS/utl</dbutilfiledir>

Thank you once again,
Kindly Address my queries