Click to See Complete Forum and Search --> : Search + replace in whole director + sub dirs?


Nick Wilson
09-20-2001, 10:49 AM
Hi
I need to search and replace a string in every file in a directory, including its sub directories.

Example

string="http://www"
repalce="http://"

I'm usin KDE if that helps!


Much thanks


Nick Wilson

slacker_x
09-20-2001, 11:49 AM
I think the way to do this is something like this:

I don't really know if this is correct, but I was thinking you could pipe the output from the find command to sed which would search through each file for the string and replace it.

I've never tried this though. Would piping the output from find just send all of the filenames to sed at one time, or send each one individually?

Nick Wilson
09-20-2001, 12:34 PM
I wouldn't know how to do that, I'm just using kedit to replace file by file ath the monent but's it's very time consuming as there are loads of files and directories under the root file.


Nick

slacker_x
09-20-2001, 12:39 PM
I'm in the same position as you....don't really know how to do it.
Take a look at man sed and man find.

make sure you have a backup copy of the files before you unleash sed on a bunch of files because it could do some real damage if you don't use it correctly.

Lem Sip
09-20-2001, 01:45 PM
I think the tool or tools you need are "grep" and "cat". Of course I haven't used them tho lol - I'm just remembering back to my Sco Unix days but I think they give the functionality you're after.

Good luck and post the results :)

Lem