How to translate from moderen editor regex to sed
syntax?
Seasoned developer, but complete sed
noob here, thank you for looking.
- Working on Pop OS Linux 20.04 LTS
- I "cook up" my regular expressions in VS Code as it matches real-time as you key in patterns, very handy!
- Attempting to edit an XML with
sed
in my Dockerfile. - I have my pattern matching in VS Code, but for the life of me can't seem to find the right
sed
command syntax. - Rewritten my regex 3 different ways, process of elimination isn't working. Cannot find what concept/syntax I'm missing here.
XML Before
<!-- HTTP Connector from upstream proxy -->
<Connector executor="tomcatConnectorThreadPool" port="8081" protocol="org.apache.coyote.http11.Http11Nio2Protocol"
connectionTimeout="3000" enableLookups="false" redirectPort="443" URIEncoding="UTF-8" bindOnInit="false"
scheme="http" proxyPort="80" />
XML After (What I'm going after)
<!-- HTTP Connector from upstream proxy -->Hello World
My Regex that works in VS Code
Search Pattern
(<!-- HTTP Connector from upstream proxy -->)(^.*)(^.*)(^.*)
Replace Pattern
VS Code back-reference = $1
$1Hello World
sed
failures
Guessing why these don't work.
Sorta hairy regex, can't interpret special characters?
sed -E 's/(<!-- HTTP Connector from upstream proxy -->\n)([<.\w="\-\s\/>]*$)/\1Hello World/g' path/to/xml.xml
Sub-sub references aren't legal?
sed -E 's/(<!-- HTTP Connector from upstream proxy -->\n)((^.*\n){3})/\1Hello World/g' path/to/xml.xml
Not sure why this doesn't work?
sed -E 's/(<!-- HTTP Connector from upstream proxy -->)\n(^.*)\n(^.*)\n(^.*)/\1Hello World/g' path/to/xml.xml
How to express these regular expressions in to proper sed
command syntax?