I have such file and I would like to replace $GLOBALS['SERVER_MEMCACHED']='localhost'; with $GLOBALS['SERVER_MEMCACHED']='mydomain.com'; using sed.
How to do this ? I don't want to replace the DB_HOST too.
<?php
$GLOBALS['DB_HOST']='localhost';
$GLOBALS['DB_NAME']='database';
$GLOBALS['DB_LOGIN']='login';
$GLOBALS['DB_PASSWORD']='password';
$GLOBALS['PORT_MYSQL']='3306';
$GLOBALS['PORT_MYSQLI']='3306';
$GLOBALS['SERVER_MEMCACHED']='localhost';
$GLOBALS['PORT_MEMCACHED']='11211';
$GLOBALS['CACHE_TIME']=600;
?>
sed -i '/SERVER_MEMCACHED/s/localhost/mydomain.com/' input
Related
I have the following line in a file:
$app-assets:"/assets/";
I am trying to use sed in the terminal to overwrite that line to read as follows:
$app-assets:"http://www.example.com/assets/";
I have tried the following but it does not work:
sed -i \'\' -e \'s/app-assets:"/assets/"/app-assets:"http://www.example.com/assets/"/g\' myfile.txt
I am fine using Perl if easier.
Use the following sed approach:
sed -i 's~\(\$app-assets:"\)\(/assets/\)"~\1http://www.example.com\2"~' myfile.txt
~ here is treated as sed subcommand separator
sed 's/app-assets:\"\/assets\/\";/app-assets:\"http:\/\/www\.example\.com\/assets\/\";/g' filename
After hacking I need clean some code add to first line on too many files.
<?php $somevar = 'some code....... ?><?php
I need clean between and include <?php $somevar and ?> because latest <?php can to be different such <html and others.
If use this I need two steeps, because not clean delimiters. I need delete delimiters also.
sed -i.bak 's/\(<?php $drnrwsrl\).*\(?>\)/\1\2/' file.php
Result
<?php $drnrwsrl?><?php
Instead of what I want
<?php
Try
sed -i.bak -E 's/(<\?php.*\(?>)(<\?php)/\2/' file.php
Using BRE without backreference:
sed -i.bak 's/<?php \$somevar[^>]*><?php/<?php/' file.php
To apply only to first line:
sed -i.bak '1s/<?php \$somevar[^>]*><?php/<?php/' file.php
I'm trying to replace all strin $PHP_SELF by $_SERVER['PHP_SELF'] in files index.php... But it seems that my syntax is wong:
sed -i 's/\$PHP_SELF/\$_SERVER\[\'PHP_SELF\'\]/g' index.php
Any idea please?
Thanks
sed -i .bak "s/\\\$PHP_SELF/\$_SERVER['PHP_SELF']/g" index.php
I want to replace the
/fdasatavol/ankit
to
/fdasatavol_sata/ankit
Can anyone help me out in this?
to write to a new file (without modifying file1):
sed 's/fdasatavol/fdasatavol_sata/g' file1 > file2
or to replace in the original file:
sed -i 's/fdasatavol/fdasatavol_sata/g' file1
This will replace each occurrence of fdasatavol with fdasatavol_sata:
sed 's/fdasatavol/&_sata/g'
If your input has occurrence of fdasatavol that are not in /fdasatavol/ankit and you don't want to substitute these then use:
sed 's#/fdasatavol/ankit#/fdastatavol_sata/ankit#g'
Note: you can use any character as sed's delimilter to aviod the confusion with the parrtern contiaing /. sed prints to stdout by default, if you are happy with the changes produced by sed you can use the -i option to store back to the file.
sed -i 's/fdasatavol/&_stat/g' file
I am trying to use sed to find/replace a string with special characters in a text file. I'm attempting to use a command like this:
sed -i -e 's/one\_test/FIRST TEST/g' tables.tex
So, replace 'one_test' with 'FIRST TEST' in tables.tex
This command doesn't work, I think because of the \ character. Does anybody know what I can do to get this working?
sed -i -e 's/one\\_test/TEST/g' tables.tex
Here is my case... if this may help
I have a string like onstar. i need to replace it with onstar_system.
i did this,
sed -i 's/onstar\./onstar_system\./g' filename
this worked for me.