2

I am reading from an XML file and want to find this property and replace the value 50 by 45 Before:

<name>ipc.client.connect.max.retries</name> 
<value>50</value>

After:

<name>ipc.client.connect.max.retries</name> 
<value>45</value>

I am using

pcregrep -M '<name>ipc.client.connect.max.retries</name>.*(\n|.)*<value>45</value>' core-site.xml  

to find the string.

I tried

sed 's/$string1/$string2' core-site.xml 

it doesnt work

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Can you post the `core-site.xml` sample file? – kev Nov 21 '15 at 01:40
  • 1
    It's been said and written many times in the past: Do not use regex to parse XML! – Nir Alfasi Nov 21 '15 at 08:23
  • fs.defaultFS hdfs://c6401.ambari.apache.org:8020 fs.trash.interval 360 ha.failover-controller.active-standby-elector.zk.op.retries 120 hadoop.http.authentication.simple.anonymous.allowed true hadoop.proxyuser.hdfs.groups – Vivek Rathod Nov 21 '15 at 23:19
  • @VivekRathod: You have to place that code in the question (where it can be properly formatted and read without reading the comments), not in a comment. – user unknown Nov 22 '15 at 07:30

1 Answers1

1

You can do that with:

sed '/<name>/{N;s/50/45/}' yourfilename

To find the tag <name> and then on the following line replace 50 with 45. To edit in place use sed -i, or for a backup of the original sed -i.bak

David C. Rankin
  • 81,885
  • 6
  • 58
  • 85