LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-04-2014, 10:14 PM   #1
rizzoid
LQ Newbie
 
Registered: May 2014
Posts: 5

Rep: Reputation: Disabled
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

Last edited by rizzoid; 05-04-2014 at 10:16 PM.
 
Old 05-04-2014, 10:33 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Almost good.
Code:
 find /home -name myfile.php -exec echo sed -i "s/smtp.live.com/mail.newone.com/g" {} \;
try it, and if it seems good, remove the 'echo'
 
2 members found this post helpful.
Old 05-05-2014, 06:25 AM   #3
rizzoid
LQ Newbie
 
Registered: May 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
It doesn't error, but it doesn't actually write to the file. The permissions are 755. Do I need to make them 777?
 
Old 05-05-2014, 06:30 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
have you tried to remove echo ?
 
1 members found this post helpful.
Old 05-05-2014, 06:36 AM   #5
rizzoid
LQ Newbie
 
Registered: May 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
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!
 
Old 05-05-2014, 06:39 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
probably you missed the flag -i ? (sed -i "s/ ...)
 
1 members found this post helpful.
Old 05-05-2014, 06:42 AM   #7
rizzoid
LQ Newbie
 
Registered: May 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
That was it! I removed the -i while testing. Awesome. Thank you so much pan64!!

Rizzoid
 
Old 05-05-2014, 06:43 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
glad to help you
if you really want to say thanks just press YES (and do not forget NevemTeve)

Last edited by pan64; 05-05-2014 at 07:01 AM.
 
1 members found this post helpful.
Old 05-05-2014, 07:01 AM   #9
rizzoid
LQ Newbie
 
Registered: May 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
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
 
Old 05-05-2014, 07:07 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
use \ before [
 
3 members found this post helpful.
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] I need to find out User disconnection cause at particualr time manalisharmabe Solaris / OpenSolaris 0 12-14-2013 06:45 AM
find out how much time an already running process is spending in user and kernel spac Valentin Linux - Newbie 3 07-05-2011 02:58 PM
How to find (various -name + delete contents but excluding some user folders in /home Virtuose Linux - Newbie 5 01-12-2011 10:16 AM
find -exec command to recursively delete files and folders in folders with X name Joan Murt Linux - Newbie 2 07-08-2009 04:35 PM
How to Find : Inactive user for a defined period of time ? avklinux Linux - General 2 01-28-2009 11:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration