using sed + find in all user folders at one time
Any help is appreciated. No rush.
I found that I could use the sed command on my CentOS server to replace certain strings in the current folder, but I'd like one elegant command to do it across multiple directories. The working sed command looks similar to this: sed -i "s/smtp.live.com/mail.newone.com/g" myfile.php And it worked well to change smtp settings in a specific file that is in every directory such as /home/user/directory. But I have to change directories for every edit. How can I add to the sed command to make this work in one line? The following test didn't work: find /home/*/directory -name \myfile.php -exec | sed -i "s/smtp.live.com/mail.newone.com/g" myfile.php Thanks. Rizzoid |
Almost good.
Code:
find /home -name myfile.php -exec echo sed -i "s/smtp.live.com/mail.newone.com/g" {} \; |
It doesn't error, but it doesn't actually write to the file. The permissions are 755. Do I need to make them 777?
|
have you tried to remove echo ?
|
Yes, I'm seeing in the output that it is appears to change the file to:
-> public $smtphost = 'mail.newone.com'; But when I check the actual file it is not rewritten. Very strange! |
probably you missed the flag -i ? (sed -i "s/ ...)
|
That was it! I removed the -i while testing. Awesome. Thank you so much pan64!!
Rizzoid |
glad to help you
if you really want to say thanks just press YES (and do not forget NevemTeve) |
One more question if you have time. I know that special characters can be a problem. How would I properly use backslash to change a password like this?
sed -i 's/FG;{U-[}-b~2c/newpass/g' I know the [ will be a problem. Thanks again. No rush Rizzoid |
use \ before [
|
All times are GMT -5. The time now is 11:07 AM. |