1

I need to update value field by searching the avp name in below .xml file .

 <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 name="Framed-IP-Address" value="0xXXXXX"> </avp>

I need to search row has "Framed-IP-Address" update value filed 0xXXXXX to 0xYYYYY

Please let me know how to do using sed or AWK or shell script any input to do this will be really helpful.

2 Answers 2

2

The right tool for this is something that is XML-aware.

XSLT (via xsltproc) or any general purpose scripting language at your disposal (Python, Ruby, Perl, node.js, even PHP-CLI) are examples of suitable tools to modify XML. sed or awk or bash script are examples of unsuitable ones.

Here's an XSLT-based solution

<!-- modify-Framed-IP-Address.xsl -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="node() | @*">
    <xsl:copy><xsl:apply-templates select="node() | @*" /></xsl:copy>
  </xsl:template>

  <xsl:template match="avp[@name = 'Framed-IP-Address']/@value">
    <xsl:attribute name="value">0xYYYYY</xsl:attribute>
  </xsl:template>
</xsl:stylesheet>

used as

xsltproc modify-Framed-IP-Address.xsl input.xml -o output.xml

will replace the attribute and save the result to output.xml.

If you don't want to use XSLT, use a scripting language you know. A Python-based solution, for example, would be in the same order of less-then-10 lines of code for such a simple task. See this thread to get an idea on how to start.

Sign up to request clarification or add additional context in comments.

Comments

1

Give a try to this sed command,

sed '/<avp name=\"Framed-IP-Address\"/s~value=\"[^"]*\"~value="0xYYYYY"~g' file

Through awk,

awk '/<avp name=\"Framed-IP-Address\"/{sub(/value=\"[^"]*\"/,"value=\"0xYYYYY\"")}1' file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.