How to replace Ip address in .xml file through shell script?

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat How to replace Ip address in .xml file through shell script?
# 1  
Old 08-25-2015
How to replace Ip address in .xml file through shell script?

I have one .xml file. which contains the following line.
Code:
<ParamString StringId="PortAddress" StringValue="172.27.166.170" />
<ParamString StringId="PortAddress" StringValue="172.27.166.171" />
<ParamString StringId="PortAddress" StringValue="172.27.166.202" />
<ParamString StringId="PortAddress" StringValue="172.27.166.203" />
<ParamString StringId="PortAddress" StringValue="172.27.167.170" />
<ParamString StringId="PortAddress" StringValue="172.27.167.171" />
<ParamString StringId="PortAddress" StringValue="172.27.167.202" />
<ParamString StringId="PortAddress" StringValue="172.27.167.203" />

I want to replace IP address to 172.27.166.178 from 172.27.166.178,
172.27.166.171 to 172.27.166.179 and so on.

I want to make it through shell script.
How to write a shell script in this regard.

Last edited by Don Cragun; 08-25-2015 at 03:01 PM.. Reason: Add CODE and ICODE tags.
# 2  
Old 08-25-2015
Quote:
Originally Posted by Anjan Ganguly
.
.
.
I want to replace IP address to 172.27.166.178 from 172.27.166.178,
.
.
.
Where's the difference?

---------- Post updated at 15:35 ---------- Previous update was at 15:33 ----------

If that's a typo, and you want to add 8 to the last byte, where to start and where to stop? All addresses?

---------- Post updated at 15:36 ---------- Previous update was at 15:35 ----------

What if you get close to /above 246?
# 3  
Old 08-25-2015
It is a typical error. It should be 172.27.166.170 in place of 172.27.166.178 i.e. replacing IP address from 172.27.166.170 to 172.27.166.178 , 172.27.166.171 to 172.27.166.179 and so on.
# 4  
Old 08-25-2015
I think we have a language barrier here. When you say "It should be 172.27.166.170 in place of 172.27.166.178", we interpret that to mean that 172.27.166.178 should be changed to 172.27.166.170 and we are confused because the string 172.27.166.178 does not appear anywhere in your sample input.
  1. Please show us the exact output you are trying to produce from your sample input (using CODE tags).
  2. Answer RudiC's question about what should happen if the replacement values overflow a valid IP address segment.
  3. And, explain whether the idea is just to increment values or whether the code is supposed to detect when the same IP address appears in the input and produce the same output for all occurrences of that that input IP address in the output.
# 5  
Old 08-25-2015
Let me clarify the think.

I want
172.27.166.178 in place of 172.27.166.170, 172.27.166.179 in place of 172.27.166.171,
172.27.166.226 in place of 172.27.166.202, 172.27.166.227 in place of 172.27.166.203 and so on.
# 6  
Old 08-25-2015
It is now clear as mud. You read an IP address from the input and your write an IP address to the output. Sometimes you add 8 to the input address to get the desired output address; sometime you add 24. How are we supposed to know what value to add (or subtract) to (or from) which input values if you don't give us a clear description of how your code is supposed to determine what random number to add or subtract from the input address?
# 7  
Old 08-25-2015
See my input from file is
Code:
<ParamString StringId="PortAddress" StringValue="172.27.166.170" /> <ParamString StringId="PortAddress" StringValue="172.27.166.171" /> <ParamString StringId="PortAddress" StringValue="172.27.166.202" /> <ParamString StringId="PortAddress" StringValue="172.27.166.203" /> <ParamString StringId="PortAddress" StringValue="172.27.167.170" /> <ParamString StringId="PortAddress" StringValue="172.27.167.171" /> <ParamString StringId="PortAddress" StringValue="172.27.167.202" /> <ParamString StringId="PortAddress" StringValue="172.27.167.203" />

My out put in the same .xml file will be,

Code:
<ParamString StringId="PortAddress" StringValue="172.27.166.178" /> <ParamString StringId="PortAddress" StringValue="172.27.166.179" /> <ParamString StringId="PortAddress" StringValue="172.27.166.226" /> <ParamString StringId="PortAddress" StringValue="172.27.166.227" /> <ParamString StringId="PortAddress" StringValue="172.27.167.178" /> <ParamString StringId="PortAddress" StringValue="172.27.167.179" /> <ParamString StringId="PortAddress" StringValue="172.27.167.226" /> <ParamString StringId="PortAddress" StringValue="172.27.167.227" />

Is that clear now?
Moderator's Comments:
Mod Comment PLEASE use CODE tags as required by forum rules for ALL sample input, ALL sample output, and ALL sample code segments.

Last edited by Don Cragun; 08-25-2015 at 05:43 PM.. Reason: Add CODE tags, again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need get data from XML file through shell script..

hi all, here is the sample log file and these errors are repeated in log file.. i need all the repeated time stamp ,severity and message tags needs to print in output file.. through shell script <log-message> <timestamp>2019-03-13T04:52:49.648-05:00</timestamp> <severity>ERROR</severity>... (17 Replies)
Discussion started by: ravi
17 Replies

2. Red Hat

How to read an xml file through shell script?

Hey , can we read an xml file and make changes in it through shell script. Thanks (4 Replies)
Discussion started by: ramsavi
4 Replies

3. Shell Programming and Scripting

Shell Script to read XML file

Hi unix Gurus, I am really new to Unix Scripting. Please help me to create a shell script which reads the xml file and from that i need to fetch a particular information. For example <SOURCE BUSINESSNAME ="" DATABASETYPE ="Teradata" DBDNAME ="DWPROD3" DESCRIPTION ="" NAME... (5 Replies)
Discussion started by: SmilePlease
5 Replies

4. Shell Programming and Scripting

Shell or perl script to replace XML text in bulk

Hi, I am looking for assistance over shell or perl (without XML twig module) which replace string in XML file under particular branch..example of code file sample.. Exact requirment : Replace "Su saldo es" in below file with "Your balance" but only in XML branch of Text id=98 and Text Id=12... (7 Replies)
Discussion started by: Ashu_099
7 Replies

5. Shell Programming and Scripting

Shell Script Xml file wallpaper

Hello, I have a custom background in my Fedora 14 OS. which changes every 10 mins, I was able to edit an Xml file for this purpose. The structure of the Xml file looks as follows : <!-- This animation will start at time shown above. --> <static> <duration>600.0</duration> ... (3 Replies)
Discussion started by: ajayram
3 Replies

6. Shell Programming and Scripting

Parse XML file in shell script

Hi Everybody, I have an XML file containing some data and i want to extract it, but the specific issue in my file is that the data is repeated some times like the following example : <section1> <subsection1> X=... Y=... Z=... <\subsection1> <subsection2> X=... Y=... Z=...... (2 Replies)
Discussion started by: yassine
2 Replies

7. 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

8. Shell Programming and Scripting

i want to nvoke a xml file from a shell script

hi all , i have a shell script that performs all the steps required for deployment of a tar file .. there is a tool that helps me in finding out what files should go in that tar file... this tool is fully in xml as it invokes ant ( a build tool in java ).... i want to invoke that xml file from a... (1 Reply)
Discussion started by: sais
1 Replies

9. UNIX for Dummies Questions & Answers

need to invoke a shell script from xml file.

hi all, forgive me if this question is not relevant to this section. i have a shell file that will automatically deploy the files that are necessary and will compile them. i need to automate this management process through cruise control, for this i need to know whether it is possible for me to... (2 Replies)
Discussion started by: sais
2 Replies

10. Shell Programming and Scripting

Shell script to split XML file

Hi, I'm experiencing difficulty in loading an XML file to an Oracle destination table.I keep running into a memory problem due to the large size of the file. I want to split the XML file into several smaller files based on the keyword(s)/tags : '' and '' and would like to use a Unix shell... (2 Replies)
Discussion started by: bayflash27
2 Replies
Login or Register to Ask a Question