Concatenate a value to an existing xml attribute u

2019-07-23 14:49发布

I am working on annotating images using xml. I am using xmlstarlet and unix bash commands but I am facing some issues when I try to append a value to an existing xml attribute value. For example, I have <filename>a</filename> and I want to make it <filename>a.jpg</filename> (i.e. concatenate '.jpg' to the existing value).

I used the following piece of code but it totally overwrites the value (i.e. <filename>.jpg</filename>.

Script:

for name in *.xml; do xmlstarlet ed --inplace -u '/annotation/filename' -v .jpg "$name"; done

1条回答
贪生不怕死
2楼-- · 2019-07-23 15:27

xmlstarlet solution:

xmlstarlet ed -L -u '//annotation/filename' -x 'concat(., ".jpg")' input.xml

Quick guide: xmlstarlet ed --help

查看更多
登录 后发表回答