Skip to main content
10 events
when toggle format what by license comment
Aug 2, 2021 at 15:13 history edited AdminBee CC BY-SA 4.0
Make caveat stronger
Aug 2, 2021 at 12:46 comment added cas @user63898 awk can do regex search and replace like sed using the sub(), gsub(), and (on GNU awk) gensub() functions. with capture groups. Processing XML, though, should be done with an xml parser (like xmlstarlet or xq, or with an xml parsing library for perl or python or whatever), not with regular expressions. Also worth looking at it xml2, which converts XML to a line-oriented format suitable for use with line-oriented tools like sed.
Aug 2, 2021 at 12:40 comment added AdminBee @Kusalananda of course. Had I known that this was about true XML parsing, I would not have suggested that. But the answer does what the OP originally asked about, so I hink I will let it stand for the time being. The caveats I placed on top should alert any future reader about the shortcomings ...+
Aug 2, 2021 at 11:28 comment added Kusalananda You may want to test this with an XML file having an attribute called os2020 and/or an attribute value that is 2020-01-01 or vision 2020 or whatever, you get what I mean. And you don't even look at the node's tag name.
Aug 2, 2021 at 11:05 comment added AdminBee I see. If that is the case, please state this in your question from the beginning. In your case, since your actual question starts to deviate substantially from the posted one, please open a new question including all relevant conditions (i.e. actual, if possibly anonymized, XML content along with desired results). You may still want to accept one of the answers here that most closely did what you were asking for in the question originally.
Aug 2, 2021 at 11:03 comment added user63898 the awk is working but i need the sed feature that can search and replace in file using regexp groups that is the text that captured will be replaces with comment xml tags ( <!-- \1 --> )
Aug 2, 2021 at 11:02 history edited AdminBee CC BY-SA 4.0
Updated information - OP actually wants to parse XML
Aug 2, 2021 at 10:24 history edited AdminBee CC BY-SA 4.0
Rephrase explanation
Aug 2, 2021 at 10:15 history edited AdminBee CC BY-SA 4.0
Add more explanation
Aug 2, 2021 at 10:02 history answered AdminBee CC BY-SA 4.0