1

In coverage.xml, I would like to replace the filename using sed and get the coverage.xml updated.

I am using sed -r 's~venv.*/(.*\")(.*)~location/here/src/\1\2~g' coverage.xml > newcoverage.xml

where coverage.xml has <class branch-rate="0" complexity="0" filename="venv/lib/python3.6/site-packages/test/src/abc.py" line-rate="0.9221" name="abc.py">

and expected output <class branch-rate="0" complexity="0" filename="location/here/src/abc.py" line-rate="0.9221" name="abc.py">

This works fine in local sh, but in jenkins the output is
<class branch-rate="0" complexity="0" filename="location/here/src/

And the capture groups \1\2 are not added.

Also tried sed -E 's~venv.*/(.*\")(.*)~location/here/src/\1\2~g' coverage.xml > newcoverage.xml but the result is same

swathi
  • 21
  • 2
  • Please show valid XML and your desired output (no description, no images, no links) for that sample input to your question (no comment). – Cyrus Jan 10 '22 at 20:43
  • 1
    Please [Don't Parse XML/HTML With Regex.](https://stackoverflow.com/a/1732454/3776858). I suggest to use an XML/HTML parser (xmlstarlet, xmllint ...). – Cyrus Jan 10 '22 at 20:44

1 Answers1

1

this worked finally. I had to escape like this for Jenkins:

sed -r 's~venv.*\\/(.*\\")(.*)~location/here/src/\\1\\2~g' coverage.xml > newcoverage.xml

swathi
  • 21
  • 2