Replace Directory Name

I am using the find command to get a list of files in a directory with all of it's sub directories and I put that in a temp file. I then want to read through that list and use the copy command to copy them to another directory for a db backup. How would I change the directory name of the files while I am looping through the file. For example:

I have a file /u01/mydb/TEST/datafile1.dbf in a variable $fn. I want to change the directory to /u02/backup/TEST/datafile1.dbf.

How do I do that? I tried sed and it didn't work to well. I also tried tr but it wasn't working. Thanks for your help.

You didn't say which shell you are using, but in ksh you can do...

var=/u02/backup/${fn#/u01/mydb/}

Note: ${fn#pattern} means remove pattern from the beginning of $fn

That works. Thanks.