Script need to do update xml file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script need to do update xml file
# 1  
Old 07-05-2014
Script need to do update xml file

Code:
<avp name="CC-Request-Type" value="1"> </avp>
      <avp name="CC-Request-Number" value="0"> </avp>
      <avp name="Subscription-Id">
      <avp name="Subscription-Id-Type" value="0"></avp>
      <avp name="Subscription-Id-Data" value="4081234567"></avp>
</avp>
        <avp name="Framed-IP-Address" value="0x3C3C3C04"> </avp>

Hi I need to update value="0x3C3C3C04" to value="0xXXXXX" by searching
string "Framed-IP-Address" in .xml file

Please let me know how to do this using SED or AWK ?

Last edited by Scrutinizer; 07-05-2014 at 06:23 AM.. Reason: CODE tags
# 2  
Old 07-05-2014
Be wary while using the -i switch.

Code:
sed -i 's/avp name="Framed-IP-Address" value="0x3C3C3C04"/avp name="Framed-IP-Address" value="0xXXXXX"/' file

# 3  
Old 07-05-2014
Thanks I tried above line its not working its not updating the value
and one more thing I want to search by Frame-IP-Address and update value filed , i can't give value in script .

below is my xml file

Code:
 <send channel="channel-1">
    <action>
      <inc-counter name="HbH-counter"> </inc-counter>
      <inc-counter name="EtE-counter"> </inc-counter>
      <inc-counter name="session-counter"> </inc-counter>
      <set-value name="HbH-id" format="$(HbH-counter)"></set-value>
      <set-value name="EtE-id" format="$(EtE-counter)"></set-value>
      <set-value name="Session-Id" format=".;1096298324;silver;$(session-counter)"></set-value>
    </action>
    <command name="CCR">
      <avp name="Session-Id" value="value_is_replaced"> </avp>
      <avp name="Auth-Application-Id" value="16777238"></avp>
      <avp name="Origin-Host" value="blade13-rhel-sgca"> </avp>
      <avp name="Origin-Realm" value="cisco.com"> </avp>
      <avp name="Destination-Realm" value="pcrf.cisco.com"> </avp>
      <avp name="Destination-Host" value="PCRF"> </avp>

      <avp name="CC-Request-Type" value="1"> </avp>
      <avp name="CC-Request-Number" value="0"> </avp>
      <avp name="Subscription-Id">
      <avp name="Subscription-Id-Type" value="0"></avp>
      <avp name="Subscription-Id-Data" value="4081234567"></avp>
</avp>
        <avp name="Framed-IP-Address" value="0x3C3C3C04"> </avp> 
 <!--  <avp name="Framed-IPv6-Prefix" value="0x008040010DB8AC10FE010000000000000000"> </avp>  -->
  <!--       <avp name="Framed-IPv6-Prefix" value="0x008020010000001000001234567FAB12000A"> </avp> -->
     </command>
  </send>


Last edited by Scrutinizer; 07-05-2014 at 06:23 AM.. Reason: CODE tags
# 4  
Old 07-05-2014
try

Code:
 awk '/Framed-IP-Address/{gsub(/0x3C3C3C04/,"0xXXXXX")}1' file


Last edited by protocomm; 07-05-2014 at 06:18 AM..
# 5  
Old 07-05-2014
Thanks lot , I trying to writ in shell script but $IP working in SED any input please ?

Code:
#!/bin/bash

infile=$1
ip=$2
 
 sed  's/name="Framed-IP-Address" value=.*/name="Framed-IP-Address" value=$ip \>\<\/avp>/' $infile > tmpfile.xml ; mv tmpfile.xml $infile


Last edited by Don Cragun; 07-05-2014 at 01:16 PM.. Reason: Add CODE tags.
# 6  
Old 07-05-2014
Quote:
Originally Posted by gstar
Thanks lot , I trying to writ in shell script but $IP working in SED any input please ?

Code:
#!/bin/bash

infile=$1
ip=$2
 
 sed  's/name="Framed-IP-Address" value=.*/name="Framed-IP-Address" value=$ip \>\<\/avp>/' $infile > tmpfile.xml ; mv tmpfile.xml $infile

Parameters are not expanded inside single quotes. Try this instead:
Code:
#!/bin/bash
infile="$1"
ip="$2"
sed  's|name="Framed-IP-Address" value=.*|name="Framed-IP-Address" value="'"$ip"'"></avp>|' "$infile" > tmpfile.xml && mv tmpfile.xml "$infile"

Note also that by changing the ";" between the sed and the mv commands to "&&" the mv will be skipped if the sed fails.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Update particular tag in a XML file

Below is the content in my XML file <name>XXX</name> <eventType>Uptime</eventType> <eventType>Delay</eventType> <eventType>Delay</eventType> <name>YYY</name> <eventType>Uptime</eventType> <eventType>Delay</eventType> ... (12 Replies)
Discussion started by: Viswanatheee55
12 Replies

2. Shell Programming and Scripting

How to retrieve values from XML file and update them in the same position! PLEASE HELP?

Good Day All Im quiet new to ksh scripting and need a bit of your help. I am attempting to write a script that reads in an XML and extracts certain field values from an XML file. The values are all alphanumeric and consist of two components: e.g "Test 1". I need to to create a script that... (2 Replies)
Discussion started by: JulioAmerica
2 Replies

3. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

4. Shell Programming and Scripting

Find and update line in xml file

Hi, I have a xml file that I need to modify 1 line to change some value from 2 to 10 (or any number). Sample input: <!-- some text here> . . . <message:test name="ryan"> <message:sample-channel charset="UTF-8" max-value="2" wait="20"> ... (5 Replies)
Discussion started by: brichigo
5 Replies

5. Shell Programming and Scripting

Positional Update of XML File

Hello, I have a XML file and need to update the data for a specific XML Attribute in the file. I need a Perl or Awk command to look for <INTERCHANGE_CONTROL_NO>000000601</INTERCHANGE_CONTROL_NO> in the XML file and change the first two 0 of the value to 9. For instance ... (4 Replies)
Discussion started by: Praveenkulkarni
4 Replies

6. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

7. Shell Programming and Scripting

perl script to update a xml file

Hi experts, I have a set of xml files in folder which has the below field. <mm:sessionID>157.235.206.12900397BE4:A</mm:sessionID>, I need to update this field regularly with new session id, which I have it from a login file. Can anyone tell me how to add a new value in <mm:sessionID>... (3 Replies)
Discussion started by: amvarma77
3 Replies

8. Shell Programming and Scripting

Perl: update lastmod in xml file

I'm trying to write a perl script that I can run as a cron job in root of my web server that will look for .shtml files get their last modified date and replace it in the sitemap_test.xml file. the problem is the substitution doesn't work and when I print to MYFILE it adds the lastmod to the end of... (3 Replies)
Discussion started by: skilodge
3 Replies

9. Shell Programming and Scripting

How to update data between xml tags

Is there a way to modify Non Null data between <host> and </host> tags to a new value ?- may be using sed/awk? I tried this sed 's|.*<host>\(?*\)</host>.*|\<host>xxx</host>|' but it is updating the host which has null value - want opposite of this - Thanks in advance for you help!! For... (2 Replies)
Discussion started by: harry_todd
2 Replies

10. Shell Programming and Scripting

How to remove xml namespace from xml file using shell script?

I have an xml file: <AutoData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Table1> <Data1 10 </Data1> <Data2 20 </Data2> <Data3 40 </Data3> <Table1> </AutoData> and I have to remove the portion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" only. I tried using sed... (10 Replies)
Discussion started by: Gary1978
10 Replies
Login or Register to Ask a Question