To change Specific Lines in An XML file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To change Specific Lines in An XML file
# 1  
Old 01-09-2013
Wrench 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
Code:
 /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
Code:
 /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 Smilie

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

Last edited by Franklin52; 01-09-2013 at 03:48 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 01-09-2013
Code:
sed  "s/s_virtual_hostname\">lnxdb-pts-[0-9]*/&-vip/"  <filename>

if you have GNU sed you can use

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

This User Gave Thanks to gowtham.varma For This Post:
# 3  
Old 01-09-2013
it worked, but there is one more requirement,

thanks gowtham

Code:
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

Code:
<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 =========

Code:
<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........
Code:
<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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Moving XML tag/contents after specific XML tag within same file

Hi Forum. I have an XML file with the following requirement to move the <AdditionalAccountHolders> tag and its content right after the <accountHolderName> tag within the same file but I'm not sure how to accomplish this through a Unix script. Any feedback will be greatly appreciated. ... (19 Replies)
Discussion started by: pchang
19 Replies

2. UNIX for Beginners Questions & Answers

Extracting specific fields from an XML file

Hello All, I have a requirement to split the input.xml file different files and i have tried using earlier examples(where i have posted in the forum), but still no luck Here is my input.xml <jms-system-resource> <name>UMSJMSSystemResource</name> ... (4 Replies)
Discussion started by: Siv51427882
4 Replies

3. Shell Programming and Scripting

Extract the specific tags in a XML file

Hello Shell Gurus, I have a requirement to get the specific tags from a XML file. Here is my code snippet <jdbc-system-resource> <name>SDPData Source</name> <target>AdminServer,osb_server1,soa_server1</target> ... (30 Replies)
Discussion started by: Siv51427882
30 Replies

4. UNIX for Beginners Questions & Answers

How to change values in xml file?

I have xml file like below, i want change the values at default-value place of each argument name using shell script. like where argument name= protocol and default-value=tcp, where argument name =port and default-value= 7223, where argument name = username and default-value=test, example ... (12 Replies)
Discussion started by: s1s2s3s4
12 Replies

5. Shell Programming and Scripting

Overwrite specific column in xml file with the specific column from adjacent line

I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file. Here is the file. <!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies

6. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

7. Shell Programming and Scripting

How to add the multiple lines of xml tags before a particular xml tag in a file

Hi All, I'm stuck with adding multiple lines(irrespective of line number) to a file before a particular xml tag. Please help me. <A>testing_Location</A> <value>LA</value> <zone>US</zone> <B>Region</B> <value>Russia</value> <zone>Washington</zone> <C>Country</C>... (0 Replies)
Discussion started by: mjavalkar
0 Replies

8. Shell Programming and Scripting

How to change a number on a specific lines in a file with shell?

Hello My problem is that I want to change some specific numbers in a file. It is like, 2009 10 3 2349 21.3 L 40.719 27.388 10.8 FRO 7 0.8 1.1LFRO 2.6CFRO 1.1LMAM1 GAP=157 1.69 5.7 5.9 5.8 0.5405E+01 0.4455E+00 0.1653E+02E STAT SP IPHASW D HRMM SECON CODA AMPLIT... (11 Replies)
Discussion started by: miriammiriam
11 Replies

9. Shell Programming and Scripting

converting specific XML file to CSV

Hi, i would convert the following XML file : <?xml version="1.0" encoding="UTF-8" ?> <files xmlns="http://www.lotus.com/dxl/console"> <filedata notesversion="6" odsversion="43" logged="yes" backup="no" id="C12577E6:004B0DA3" iid="C12577E6:004B0DA8" link="1" dboptions="0,524288,0,0"> ... (24 Replies)
Discussion started by: Nicol
24 Replies

10. UNIX for Dummies Questions & Answers

how to display specific lines of a specific file

are there any basic commands that can display lines 99 - 101 of the /etc/passwd file? I'm thinking use of head and tail, but I forget what numbers to use and where to put /etc/passwd in the command. (2 Replies)
Discussion started by: raidkridley
2 Replies
Login or Register to Ask a Question