Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rename multiple files and use dd 1

Status
Not open for further replies.

ksbrace

Programmer
May 13, 2000
501
US
Hello,
I'm working on automating some database refreshes(clones) and I have to move some files using dd.

This is what I have so far:
for i in `find /orabak/oraclebkups/prod92/ -name "*.dbf" -print`; do
dd if=$i of=/oradata/devl92/$i bs=262144
done

But, I want to just get the file name from the find command and I want to be able to rename the file. For instance, when I run the above find command by itself, this is what I get( I truncated the results):
/orabak/oraclebkups/prod92/system01.dbf
/orabak/oraclebkups/prod92/development_PROD_01.dbf

Now, I want to just grab the filename. I also want to make the PROD become DEVL in any of the filenames that has the word PROD in it.

any help would be greatly appreciated. Thanks,




 
Something like this ?
for i in `find /orabak/oraclebkups/prod92/ -name "*.dbf" -print`; do
j=`echo $i | sed 's!.*/!!;s!PROD!DEVL!'`
dd if=$i of=/oradata/devl92/$j bs=262144
done

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,
Ok, great! Now, if time permits, do you mind breaking down the second line for me and explaining what is going on there? Thanks again!
Kelly

 
I simply used sed to remove the directory path and replace PROD by DEVL

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Note that the basename command could have been useful here too.

[tt]# basename /blah/blah/yak
yak
#[/tt]


Annihilannic.
 
I agree with Annihilannic (again).

basename is the preferred way to remove the path.


Trojan.
 
You can replace basename with inbuilt ksh parameter substitution for better performance

$ fullpath="/blah/blah/yak"
$ echo ${fullpath##*/}
yak
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top