
September 19th, 2004, 01:43 PM
|
|
Registered User
|
|
Join Date: Sep 2004
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
how to use sed to search replace files throughout a directory tree
Ok, i got most of my sed script working. i basically have two files that rely on each other, one file is the shell script, which calls sed to perform a sedscript, output to a file, and replace the original file (this needs to be done or sed does not commit the changes to the document!) the other file tells what sed is to do.
so my shell script is:
#Script name is shellscript
sed -f sedscript filename.txt > tempfile
mv tempfile filename.txt
this script tells sed to read a script called sedscript, execute the commands it contains, output to a file named nice, and then rename/overwrite nice to the original filename. so basically, i would invoke the script by typing: shellscript
now here is my sedscript:
s/Apples/Oranges/g
this says to replace the word Apples with Oranges.
so here is my question.... i figured out how to create a script that search/replace MULTIPLE files with appropriate values, but i dunno how to make it search/replace for a file NOT in the directory where the sedscript is invoked. how can i make the script look for filename.txt in a directory that is one up/down/etc? i tried putting a simple cd.. into the script but then the sedscript wont be in a different directory so sed doesnt know what to do.
also, i dont think i can use a find command because i dont want to replace filename.txt from other directories -- just directories from the current one on down.
and no, i cant use perl because its not installed. thanks!
|