zhuanyi
1
Hi,
First post for a noob so please go easy with me
I have a XML block that is originally like this:
<SETNAME>somecrap/THIS</SETNAME>
and I would like it be replaced with, in the original file:
<SETNAME>THIS</SETNAME>
I tried to use:
sed 's/.*\<SETNAME\>.*/\<SETNAME\>THIS\</SETNAME\>/g' folder/file.xml
And it returned:
sed: command garbled:
I then replaced sed with perl -pi -e but ended up having this error message:
Search pattern not terminated at -e line 1.
Could you please help? This is a step in my bash script running in Unix.
Thanks a lot!
Scott
2
Instead of using sed "s/.../.../g", use an alternative delimiter. i.e. sed "s@...@...@g".
1 Like
zhuanyi
3
That totally did the trick, thanks so much and I am glad that I have found such an active community to help me out!
Try it this way:
$ echo '<SETNAME>somecrap/THIS</SETNAME>' |
sed 's|\(<SETNAME>\)[[:alnum:]]*/\([[:alnum:]]*<\/SETNAME>\)|\1\2|'
<SETNAME>THIS</SETNAME>
1 Like
zhuanyi
5
Thanks spacebar, Scott's method worked for me so I guess I'll use his
Thanks a lot for your help though!