Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
The problem that you'll have using find is that it will try to feed the directories to the programme doing the substitution, as well as the files, causing it to bomb. (I just wrote a little shell script to test this and that's what happened.)
I will consider this further and report back if I find a solution - it's a "real world" problem that must have a simple answer!
* the first s is substitue (someone correct me if I'm wrong!)
* between the first and second slashes is the string you want changed
* between the second and third slashes is what you want the string changed to
* the g means do all occurences, not just the first one (g=global)
Note - if you want to have / or other reserved characters in your string(s), you will need to escape it with a backslash \.
Not sure on your last example - do what I did with mine and try it!
I just set up a temporary directory with a file in it containing the the string I wanted to change and a subdirectory with a further file also containing that string. Then I tweaked and ran the code until it worked, making many references to the find manpage in the process...
1) experiment - just not on live data ;-)
2) manpages Are Your Friends.
I think that the trucation issue is a case of "your mileage may vary" (it's a buffering thing, I think), but Alex's solution is actually better practice than my original suggestion.
As a rule, it's probably best NOT to take the contents of a file, process it and then put it back in - all in one step. If your process doesn't involve taking a copy, just use a temporary file and delete it afterwards.