-1

I have managed to replace 1 xml file. However, I have 10 of them from test1.xml to test30.xml and they have different Paths at the end:

test1.xml
...
<examples>
<example path='/test/test123/st1.txt'/>
<examples>
...
test2.xml
...
<examples>
<example path='/test/test123/te2.txt'/>
<examples>
...

to

test30.xml
...
<examples>
<example path='/test/test123/removethispart.txt'/>
<examples>
...

to this:

...
<examples>
<example path='/test/test123/'/>
<examples>
...

Previously, I used this and it can change one file sed -i "s#<example path='/test/test123/st1.txt'/>#<example path=/test/test123/>#" test1.xml

However, I would like to change multiple files at once and the below script executed but upon cat the xml file, it did not show the changes

sed -i "s#<example path='/test/test123/*.txt'/>#<example path='/test/test123/'>#" *.xml

Any help would be greatly appreciated. Thanks for your time!

Alan Chu
  • 15
  • 2
  • 7
  • 1
    Does this answer your question? [Using SED with wildcard](https://stackoverflow.com/questions/9189120/using-sed-with-wildcard) – Ryszard Czech Sep 18 '20 at 20:40

1 Answers1

0

You are almost there. Try

sed -i "s#<example path='/test/test123/.*\.txt'/>#<example path='/test/test123/'>#" *.xml

With regular expressions, the pattern to match anything is .* and a literal period needs to be quoted with a backslash, \..

Jon
  • 3,573
  • 2
  • 17
  • 24