![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
With sed:
Code:
sed 's/disable_functions = .*/disable_functions = exec/' php.ini > file.tmp mv file.tmp php.ini Code:
sed -i 's/disable_functions = .*/disable_functions = exec/' php.ini Code:
awk '$0 ~ /disable_functions = /{print "disable_functions = exec";next}1' php.ini > file.tmp
mv file.tmp php.ini
|
|
#3
|
|||
|
|||
|
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
|
|
#4
|
|||
|
|||
|
Kool... thanks a lot.
|
|||
| Google The UNIX and Linux Forums |