1

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.

gregory
  • 9,068
  • 2
  • 26
  • 37
user3139545
  • 6,070
  • 10
  • 38
  • 78
  • You know the thing about using regex for XML? [ZA̡͊͠͝LGΌ ISͮ̂҉̯͈͕̹̘̱ TO͇̹̺ͅƝ̴ȳ̳ TH̘Ë͖́̉ ͠P̯͍̭O̚​N̐Y̡ H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – tripleee Jun 18 '18 at 08:33

1 Answers1

1

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.

anubhava
  • 713,503
  • 59
  • 514
  • 593