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.
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.