I have the large xml file with the following type of lines:
<test type="one" valid="yes" description="something">
twilight-.*\.iso\.auth</test>
<test type="one" valid="no" description="something else">
testlite-.*\.cop</test>
<test type="two" valid="yes" description="something else">
messing-.*\.cop\.auth</test>
<test type="three" valid="yes" description="something else">messing-.*\.cop\.auth</test>
There are many such lines in my xml file. My requirement is that:
- If we match the pattern 'valid="yes"' in the first line and '.auth' in the second line, then duplicate both the lines. And in the second line, replace ".auth" with ".newauth"
- If we match BOTH the patterns 'valid="yes" and '.auth' in the same line, then duplicate only that line and replace ".auth" with ".newauth"
Here is how the output should look like:
<test type="one" valid="yes" description="something">
twilight-.*\.iso\.auth</test>
<test type="one" valid="yes" description="something">
twilight-.*\.iso\.newauth</test>
<test type="one" valid="no" description="something else">
testlite-.*\.cop</test>
<test type="two" valid="yes" description="something else">
messing-.*\.cop\.auth</test>
<test type="two" valid="yes" description="something else">
messing-.*\.cop\.newauth</test>
<test type="three" valid="yes" description="something else">messing-.*\.cop\.auth</test>
<test type="three" valid="yes" description="something else">messing-.*\.cop\.newauth</test>
Note that, there are many such lines(pairs of lines) in my xml file that needs to be replaced. But the rule to replace it remains the same as above. Also, note that for the fourth line, the entire xml tag is part of a single line. So, the awk expression becomes a little more complicated in this case.
Thanks in Advance!