xml - Sed: substitute pattern, not limited to matching line, but to another pattern -
I want to enclose many words with quotation marks. Sed and worked easily with the group.
Except that my words are located in the attribute of an XML tag.
& lt; Daddy & gt; & Lt; Son name = "blabla" & gt; & Lt; Related = "car cat doll" color = "yellow" /> & lt; / Son & gt; & Lt; / Papa & gt;
I want to postprocessed the
attribute to
"car" cat "doll" "
.
is a specially affected attribute name. Therefore, there is no risk of matching this word only, it will automatically be a part of a related
tag, I think it is a good start That you are able to use here, and do not do harsh things with heavy equipment, and XML reader.
Take my first attempt To filter bins was to match the pattern, and try to surround the words but it surrounds them, matches the whole line, and not only in the first pattern, which I wanted.
sed "/ having = \" [az] \ + \ "/ s / \ ([az] \ + \) / '\ 1' / g"
.
& lt; papa & gt; son name = "blabla" & gt; & lt; 'related' '=' 'car' 'cat' 'doll '' Color '=' 'Yellow' '' & gt; & lt; / son & gt; & lt; / pg & gt;
My second option with group matching Trust grows not ahead of me ...
sed "s / havings = \" \ ([az] \ + \) \? \) * \ "/ Havings = \" '\ 2' \ "/ g"
.
& lt; Dad & gt; & Lt; Son name = "blabla" & gt; & Lt; Related = "'doll' 'color =" yellow "/> gt; & lt; / dad & gt;
sed ": a / being / {s / \" \ (\ (* '[^] \ {1, \}' \) * * \) \ ([^ '\ "] \ {1, \} \) \ ([^ \ ^] * \) \" / \ "quotation mark" by changing each group of the word (space or Quotations, or double quotes) "\ 1 '\ 3' \ 4 \" / ta} "YourFile
After all the group of words surrounded by simple quotation, a double quote Using a recursive to change the middle The reason for this, the option g
can not be used again with reference, so use the group using a large group of all the words already cited, unless it contains No other word
I think the content is in the form of a line (due to the default behavior) and ones
Comments
Post a Comment