The title may be a bit vague, but I have a file that contains something like this
<Tag>
<Tag
111
222
/>
</Tag>
Using bash script (grep, sed, awk, etc.) I want to search for the inside tag and replace it with some new content
<Tag>
<Tag
333
444
/>
</Tag>
The new content can be all in one line, ie <Tag 333 444 />
I'm struggling with how to search for the inside Tag only, I can't find a way to extract a string starting with <Tag
and end with />
but doesn't contain >
. Any help would be appreciated.
CodePudding user response:
If this, using GNU sed for -E
and -z
, isn't all you need then edit your question to provide more truly representative sample input/output including cases you have that this doesn't work for:
$ sed -Ez 's:<Tag[^<>] />:<Tag 333 444 />:' file
<Tag>
<Tag 333 444 />
</Tag>