Answer the question
In order to leave comments, you need to log in
Bash: Replacing matches between certain strings?
Please tell me how can I replace the text that is between the line that contains AAA and the line that contains BBB.
Text example:
<Directory /var/www/123.ru>
Options -Includes +ExecCGI
FCGIWrapper /var/www/php-bin/test/php .php
FCGIWrapper /var/www/php-bin/test/php .phtml
</Directory>
<Directory /var/www/123.ru>
and </Directory>
Answer the question
In order to leave comments, you need to log in
#!/bin/bash
FILE="$1"
PATTERN="$2"
PATH1=$3
PATH2=$4
LINES=$(grep -n -A4 "${PATTERN}" ${FILE} | grep FCGI | cut -d "-" -f1)
for line in ${LINES}
do
sed -i "${line}s|${PATH1}|${PATH2}|" ${FILE}
done
cat ${FILE}
cp ${FILE} ${FILE}.bk
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question