Sed Replace A Multi-Line String: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 77: Line 77:
|-
|-
|valign="top"|
|valign="top"|
'''${HOME}/Documents/sed_playground/000-default.conf'''
<source lang="apache">
<source lang="apache">
#
#
Line 92: Line 93:


|valign="top"|
|valign="top"|
'''${HOME}/Documents/sed_playground/000-default.conf'''
<source lang="apache">
<source lang="apache">
#
#

Revision as of 03:56, 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}

${HOME}/Documents/sed_playground/000-default.conf
#
#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>
${HOME}/Documents/sed_playground/000-default.conf
#
#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>