XML : Perl replace strings in XML file if unequal

I have an XML file with values like the following:

  <values val1="4124" val2="21341"></values>  <values val1="1234" val2="231"></values>  <values val1="814" val2="8943"></values>    

I would like to make val2 assume the value of val1 in all cases where they're unequal.

So the above would become:

  <values val1="4124" val2="4124"></values>  <values val1="1234" val2="1234"></values>  <values val1="814" val2="814"></values>    

Here is what I have:

  perl -pi -e 's,val2=\"[0-9]*\,val1=\"[0-9]*\,g;' *    

I am mainly having trouble understanding how to substitute the value of val1 to val2. My above code will do this:

  <values val1="4124" val1="4124"></values>    

No comments:

Post a Comment