The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
find and replace string in a directory files koti_rama Shell Programming and Scripting 2 05-30-2008 12:48 AM
Need to search and replace in multiple files in directory hierarchy umen Shell Programming and Scripting 3 12-24-2007 01:56 AM
Replace a Directory path with another in a file venkatajay_18 Shell Programming and Scripting 3 10-17-2006 12:52 PM
Replace characters in all file names in a particular directory madhunk Shell Programming and Scripting 4 02-16-2006 04:10 PM
moving files from a unix directory to a windows directory gleads UNIX for Dummies Questions & Answers 2 08-29-2002 05:42 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-25-2004
Registered User
 

Join Date: Nov 2001
Posts: 59
Question 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.
Reply With Quote
Forum Sponsor
  #2  
Old 03-25-2004
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
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
Reply With Quote
  #3  
Old 03-25-2004
Registered User
 

Join Date: Nov 2001
Posts: 59
Thanks.

That works. Thanks.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0