nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Comment out lines in .htaccess using sed command

This is a discussion on Comment out lines in .htaccess using sed command within the Shell scripting forums, part of the Development/Scripting category; Hello, I need a script that changes in .htaccess all occurrences of: php_flag magic_quotes_gpc on php_value max_execution_time 60 php_flag magic_quotes_runtime ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-07-2009, 06:19 PM
Junior Member
User
 
Join Date: Jul 2008
Location: SM
OS: CentOs
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
cosminnci is on a distinguished road
Default Comment out lines in .htaccess using sed command

Hello,

I need a script that changes in .htaccess all occurrences of:
php_flag magic_quotes_gpc on
php_value max_execution_time 60
php_flag magic_quotes_runtime off
php_flag asp_tags off
php_flag register_globals on

and other variations of php_*a*
need to insert # in front.

would try with sed
sed -e 's/^php_*a*/#php../g' myfile.txt

what is the correct syntax for this?
could also encounter other "php" occurences in the file.
Reply With Quote
  #2 (permalink)  
Old 04-07-2009, 12:42 AM
Member
User
 
Join Date: May 2009
OS: Mandriva
Posts: 78
Thanks: 0
Thanked 14 Times in 14 Posts
Rep Power: 2
cfajohnson has a spectacular aura about cfajohnson has a spectacular aura about
Default

Quote:
Originally Posted by cosminnci View Post
Hello,

I need a script that changes in .htaccess all occurrences of:
php_flag magic_quotes_gpc on
php_value max_execution_time 60
php_flag magic_quotes_runtime off
php_flag asp_tags off
php_flag register_globals on

and other variations of php_*a*
need to insert # in front.

would try with sed
sed -e 's/^php_*a*/#php../g' myfile.txt

what is the correct syntax for this?
could also encounter other "php" occurences in the file.

It will only match php at the beginning of a line because you anchored the regex with ^.

You could also use:

Code:
sed '/^php_*a*/ s/^/#/' myfile.txt
Reply With Quote
  #3 (permalink)  
Old 04-07-2009, 01:16 AM
Junior Member
User
 
Join Date: Jul 2008
Location: SM
OS: CentOs
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
cosminnci is on a distinguished road
Default [Solved] comment lines in .htaccess

It works.
Thank You.

Code:
 sed -i '/^php_*a*/ s/^/#/' myfile.txt
used it with -i edit files in place

Last edited by nixcraft; 04-07-2009 at 11:31 AM.
Reply With Quote
Reply

Tags
.htaccess , apache , sed , update text file


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
BIND named.conf search zone and comment it out script asim.mcp Shell scripting 2 15-06-2009 12:39 PM
Shell script to count number of lines in file specified by the second command-line seaman77 Shell scripting 1 16-03-2009 07:46 PM
htaccess + invalid command ephdia Web servers 0 19-09-2008 03:37 PM
Lighttpd Gallery2 URL Rewrite (.htaccess) SEO Rules rootadmin Web servers 2 22-06-2008 06:57 PM
.htaccess problems rcordeiro Linux software 4 05-07-2006 07:32 PM


All times are GMT +5.5. The time now is 07:59 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38