Reputation: 7374
Given 100 XML files that can contain UUIDs I want to find all UUIDs and add an underscore to the beginning of that UUID. The content of the XML file can look different but an example is:
<bpmndi:BPMNEdge bpmnElement="627b6548-aa19-47c6-a87c-31017810a934-_jbpm-unique-3490" >
I want to transform this to:
<bpmndi:BPMNEdge bpmnElement="_627b6548-aa19-47c6-a87c-31017810a934-_jbpm-unique-3490" >
What I have so far is a regexp to find all UUIDs:
ag [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
The problem is that most other articles I have found either is for how to start the line that contains a match with some character or to replace the whole line. I just want to add a character to the match.
Upvotes: 1
Views: 51
Reputation: 784878
Your regex is correct. You can use that in sed
as:
sed -i.bak -E 's/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/_&/g' file
Replacement expression _&
will prefix matched text with underscore.
Upvotes: 1