Find and replace from an XML

Input-xml

<weblogic-web-app>
  <session-descriptor>
    <session-param>
      <param-name>SysName</param-name>
      <param-value>smilyface</param-value>
    </session-param>
    <session-param>
      <param-name>InternetProtocol</param-name>
      <param-value>xxxxxxxx</param-value>
    </session-param>
    <session-param>
      <param-name>Timeout</param-name>
      <param-value>600s</param-value>
    </session-param>

I have a number of xml files in each systems. I need to replace xxxxxxxx with the system IP

Note:

  1. The value xxxxxxxx may be different in each xml files.
  2. The value InternetProtocol will be same for each xml files.

:o

awk '/InternetProtocol/ {print; getline; gsub($0,"<IP>")}{print}' <filename>

Please use code tag for code and data samples.

Try smth like this.

awk -v ip=$(hostname -i) '/InternetProtocol/{print;getline;ip=">"ip"<";sub(/>.*</,ip);}1' input_file

Cheers!!!
-R

1 Like