Sed Replace A Multi-Line String: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
(Created page with "{| |valign="top" colspan="2"| <source lang="bash"> mkdir -p ${HOME}/Documents/sed_playground sudo tee -a ${HOME}/Documents/sed_playground/000-default.conf >/dev/null <<EOF...")
 
No edit summary
Line 24: Line 24:
|colspan="2" valign="top"|
|colspan="2" valign="top"|
<source lang="bash">
<source lang="bash">
CONF_FILE="${HOME}/Documents/sed_playground/000-default.conf"
APACHE_CONF_FILE="${HOME}/Documents/sed_playground/000-default.conf"
DIRECTORY_FIND_LEAD_EXP='<Directory "\/var\/www\/cgi-bin">'
DIRECTORY_FIND_LEAD_EXP='<Directory "\/var\/www\/cgi-bin">'
</source>
</source>
Line 69: Line 69:
     N;N;N;N;N
     N;N;N;N;N
     s|${DIRECTORY_FIND_FULL_EXP}|${DIRECTORY_FILL_FULL_EXP}|
     s|${DIRECTORY_FIND_FULL_EXP}|${DIRECTORY_FILL_FULL_EXP}|
}" ${CONF_FILE}
}" ${APACHE_CONF_FILE}
</source>
</source>



Revision as of 03:32, 24 December 2022

mkdir    -p ${HOME}/Documents/sed_playground
sudo tee -a ${HOME}/Documents/sed_playground/000-default.conf >/dev/null <<EOF
#
#This is some test comments
#    Skip this
#

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options +ExecCGI
    AddHandler cgi-script .cgi .pl
    Require all granted
</Directory>
EOF

APACHE_CONF_FILE="${HOME}/Documents/sed_playground/000-default.conf"
DIRECTORY_FIND_LEAD_EXP='<Directory "\/var\/www\/cgi-bin">'

DIRECTORY_FIND_FULL_EXP=$(cat <<EOF
${DIRECTORY_FIND_LEAD_EXP}\n\
[ ]*AllowOverride None\n\
[ ]*Options +ExecCGI\n\
[ ]*AddHandler cgi-script \.cgi \.pl\n\
[ ]*Require all granted\n\
<\/Directory>
EOF
)
DIRECTORY_FILL_FULL_EXP=$(cat <<EOF
#<Directory "\/var\/www\/cgi-bin">\n\
    #AllowOverride None\n\
    #Options +ExecCGI\n\
    #AddHandler cgi-script \.cgi \.pl\n\
    #Require all granted\n\
#<\/Directory>
EOF
)

echo ""
echo "Sedding"
sed -i "/${DIRECTORY_FIND_LEAD_EXP}/{
    N;N;N;N;N
    s|${DIRECTORY_FIND_FULL_EXP}|${DIRECTORY_FILL_FULL_EXP}|
}" ${APACHE_CONF_FILE}

#
#This is some test comments
#    Skip this
#

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options +ExecCGI
    AddHandler cgi-script .cgi .pl
    Require all granted
</Directory>
#
#This is some test comments
#    Skip this
#

#<Directory "/var/www/cgi-bin">
    #AllowOverride None
    #Options +ExecCGI
    #AddHandler cgi-script .cgi .pl
    #Require all granted
#</Directory>