The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replacing a line in a file - HELP!!! maxmave Shell Programming and Scripting 1 06-04-2008 08:55 PM
Replacing a string in nth line maxmave Shell Programming and Scripting 1 06-04-2008 02:32 PM
replacing certain characters with new line? Bashar Shell Programming and Scripting 4 05-13-2007 01:34 PM
replacing variable values in all files in directories newtoshell Shell Programming and Scripting 3 12-30-2005 01:11 PM
Replacing the last field of a line. Darek Shell Programming and Scripting 3 08-19-2005 08:45 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-31-2007
Registered User
 

Join Date: Mar 2007
Posts: 87
replacing a line that may have different values on different servers

Replace disable_functions in php.ini with value of your choice which may be different on different servers
================================================


-bash-2.05b# grep disable_functions /usr/local/lib/php.ini
disable_functions = 1 2 e weq t ret rye y etyhty rt et e



-bash-2.05b# replace "$(grep disable_functions /usr/local/lib/php.ini)" "disable_functions = exec" -- /usr/local/lib/php.ini | grep disable_functions


-bash-2.05b# grep disable_functions /usr/local/lib/php.ini
disable_functions = exec





I was successful above, but how to do it the awk or sed way?


Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 12-31-2007
Moderator
 

Join Date: Feb 2007
Posts: 2,329
With sed:

Code:
sed 's/disable_functions = .*/disable_functions = exec/' php.ini > file.tmp
mv file.tmp php.ini
If your sed version support the -i option:

Code:
sed -i 's/disable_functions = .*/disable_functions = exec/' php.ini
With awk:

Code:
awk '$0 ~ /disable_functions = /{print "disable_functions = exec";next}1' php.ini > file.tmp
mv file.tmp php.ini
Regards
Reply With Quote
  #3  
Old 12-31-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Code:
substitute="newstring"
while read line
do
    case $line in 
        "disable_functions"* ) echo "disable_functions = $substitute";; 
        *) echo $line;;       
    esac
done < php.ini > newphp
mv newphp php.ini
Reply With Quote
  #4  
Old 12-31-2007
Registered User
 

Join Date: Mar 2007
Posts: 87
Kool... thanks a lot.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0