I've got a task to extract data from several Apache servers.  The task is to print out:<Directory ...>  ...</Directory>where +ExecCGI is located within.  Let me give an example to illustrate.  Assume that the Apache configuration file has numerous Directory sections as indicated below:<Directory /var/www/site1/htdocs>  Options +ExecCGI  ...  ...</Directory>.........<Directory /var/www/site1/Promo>  Options -ExecCGI  ...  ...</Directory>From above, I would only like to get the following output:<Directory /var/www/site1/htdocs>  Options +ExecCGI  ...  ...</Directory>I've searched the forums and have found posts where people have asked questions on how to print out a whole section between tags (I know how to do that), or to change certain text when found (again, I know how to do that).I will be changing the +ExecCGI to -ExecCGI, but the changes need to go through a review process and hence this question so that I can pull this data out.
Print text between tags (inclusive) if certain text is found
text processing;sed;awk;regular expression;perl
perl -l -0777 -ne 'for (m{<Directory.*?</Directory>}gs) {print if /\+ExecCGI/}'Or with GNU grep:grep -zPo '(?s)<Directory(?:.(?!</Directory))*?\+ExecCGI.*?</Directory>'