Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm having a tough time finding info online about this, maybe I'm not looking for the right things.
In any case, I need to update paths in about 50 files.
Specifically, I need to replace:
home/httpd/vhosts
with
var/www/vhosts
None of the grep examples I see address replacing strings with slashes. I did try grep -rl 'search this' . | xargs perl -pi -e's/this/that/g' and I threw in forward slahses to accomodate the backslashes, but nothing seemed to work (yes, I'm doing this on a "test" directory first!)
I was hoping for any solutions on this. Thanks a ton!!
Distribution: Slackware64 14.2 and current, SlackwareARM current
Posts: 1,634
Rep:
I'm confused by your use of the terms slash and backslash, but aside that there's another solution. grep takes any character as delimiter, furthermore it can modify files on the fly without creating any temporary files. Test it first in your test folder, but I think it should work:
Code:
sed -i "s:home/httpd/vhosts:var/www/vhosts:g"
and combine it with any other command (find, for ...) as you like to expand it to all 50 files.
Great, thank you very much!! I actually tried one of the responses, and it worked perfectly. I'm going to try the other two, just because I'm curious to know more than 1 way of doing this.
I really appreciate the responses, you've saved me a heck of a lot of time which I otherwise would have wasted changing each file manually!!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.