grep command to replace multiline text from httpd.conf file on Fedora


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep command to replace multiline text from httpd.conf file on Fedora
# 1  
Old 04-16-2009
grep command to replace multiline text from httpd.conf file on Fedora

Hi,

I am a newbie to shell scripting and to Linux environment as well.

In my project I am trying to search for following text from the httpd.conf file

<Directory '/somedir/someinnerdir'>
AllowOverride All
</Directory>

and then remove this text and again rewrite the same text.
The reason to do this rewriting is that the script will be run on first installation of the web app, but it may again be run some time later as other part of this shell script is performing other tasks as well. So for first time this text wont be found and will simply be written but later again when script is run this text will be found and will need to be removed and the written again.

So the part of my script with which I am trying to achieve this is something like :

grep -ve "<Directory '/somedir/someinnerdir'>\\n
AllowOverride All\\n
</Directory>" > tmp_direct

echo -e "<Directory '/somedir/someinnerdir'>\\n
AllowOverride All\\n
</Directory>" >> tmp_direct

mv tmp_direct >> /etc/httpd/conf/httpd.conf

I dont have the code in front of me currently so there may be some syntactical errors above but the logic/coding is same.

Above code fragment is not able to do what I want to achieve as the grep command doesnt support multiline searching.

My OS is Fedora 8.

Can you please suggest something in this code to achieve what is needed or may be some other alternative.

Any help in this regard will be highly appreciated.

Thanks in advance.
# 2  
Old 04-17-2009
To remove the part you can do something like:

Code:
awk '/<Directory /{p=1} /<\/Directory>/{p=0;next} !p' httpd.conf file > tmp_direct
mv tmp_direct httpd.conf file

You can place the removed part:

Code:
<Directory '/somedir/someinnerdir'>
AllowOverride All
</Directory>

in a file and append it again with cat file >> httpd.conf file.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need grep regex to extract multiline text between two strings

I have a file conatining the below: --- 10.9.16.116: /tmp/5835113081224811756.jar: hash: e6df90d38fa86f0e289f73d79cd2cfd2a29954eb /tmp/4603745991442278706.jar: hash: e6df90d38fa86f0e289f73d79cd2cfd2a29954eb 10.9.14.126: /tmp/conf/extra/httpd-ssl.conf: hash:... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. Red Hat

Httpd.conf Config?

hi is it possible ? explain tome about below items StartServers 8 MinSpareServers 10 MaxSpareServers 20 ServerLimit 4000 MaxClients 4000 MaxRequestsPerChild 4000 this is my servers 8gig ram & cpu 12 core... what cann i putting in order this ? tnx (1 Reply)
Discussion started by: mnnn
1 Replies

3. Shell Programming and Scripting

Search and comment block of text from apache httpd.conf

I want to search for a block of text in httpd.conf that between two strings and comment it. There are multiple blocks with "<Directory.. and </Directory>" <Directory "${ORACLE_INSTANCE}/config/${COMPONENT_TYPE}/${COMPONENT_NAME}/htdocs"> # # Possible values for the Options directive are... (3 Replies)
Discussion started by: kchinnam
3 Replies

4. Shell Programming and Scripting

How to replace word with multiline text using shell scripting.

Hi all I have data files which contain data as shown below: Line 5: FIDE INST_DESC: DIAM Co Ltd/Japan => MAID Co Ltd/Japan INST_NME: DIAM Co Ltd/Japan => MAID Co Ltd/Japan Line 6: FIDE INST_DESC: DIAM DL/Pimco US Bond Open Born in the USA => MAID DL/Pimco US Bond Open Born in the... (6 Replies)
Discussion started by: Ganesh_more
6 Replies

5. Shell Programming and Scripting

Playing with httpd.conf

Hello Guys !! wanted to use SED to pull cout the full vertualhost entry for domain which is specified from command line Like (IP base httpd.conf) domain="ServerName takemewithyou.in" sed -n '/<VirtualHost* $domain/,/<\/VirtualHost>/p' httpd.conf File can take to test is below ... (0 Replies)
Discussion started by: SilvesterJ
0 Replies

6. Shell Programming and Scripting

perl : replace multiline text between two marker points

Hi there I just wondered if someone could give me some perl advice I have a bunch of text files used for a wiki that have common headings such as ---++ Title blah ---++ Summary blah ---++ Details Here is the multiline block of text I wish to (6 Replies)
Discussion started by: rethink
6 Replies

7. Red Hat

apache 2.2 httpd.conf

Hi, I was wondering if someone could help me out here. I am super-paranoid, so am trying to limit what PHP files can be executed on this server. I have a small list of files that I want to allow. The rest, deny: <Files ~ "\.(php|php3)$"> order allow,deny deny from all </Files> I... (0 Replies)
Discussion started by: Lobster
0 Replies

8. Red Hat

apache 2.2 httpd.conf

Hi, I was wondering if someone could help me out here. I am super-paranoid, so am trying to limit what PHP files can be executed on this server. I have a small list of files that I want to allow. The rest, deny. So I have base rule that denies all php files server-wide: order allow,deny ... (0 Replies)
Discussion started by: Lobster
0 Replies

9. IP Networking

httpd.conf - stumped

Have been asked to remove all images from being logged to the access_log ... where am I going wrong?<VirtualHost 123.456.789.99> ServerName www.somedomain.com.au DocumentRoot /agents/tts Redirect /wap http://somewap.com.au/traveler LogFormat "%v %h %l %u %t \"%r\" %>s %b" comonvhost... (2 Replies)
Discussion started by: Cameron
2 Replies

10. IP Networking

defaults httpd.conf

I have found in the httpd.conf where it it states the default parse pages like index.htm, index.html, index.php and etc....However, my computer box does not seem to want to automatically load the index.php files. Anyone have any ideas? (5 Replies)
Discussion started by: macdonto
5 Replies
Login or Register to Ask a Question