Tuesday, August 23, 2011

How to locate and replace the next line

How to locate and replace the next line in a block of XML.. Ie find "findme" and then replace 80 on the next line with 100

perl -pe 'if($on == 1) { if(m/c>80/) {s/80/100/}; $on=0 };  $on=1 if m/findme/;' test.txt


<a>
  <b>findme</b>
  <c>80</c>
</a>
<a>
  <b>ignoreme</b>
  <c>80</c>
</a>

No comments:

Post a Comment