Replace Directory Name


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Replace Directory Name
# 1  
Old 03-25-2004
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.
# 2  
Old 03-25-2004
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
# 3  
Old 03-25-2004
Thanks.

That works. Thanks.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace all ip addresses in all files in directory in ksh?

Hi All, I have a directory containing a lot of files and I want to search all files which contains IP addresses pattern and want to replace those ip addresses with equal number of, say, some character, 'x'. So after replacement the file should not contain any IP address. Like 10.122.53.5 ->... (3 Replies)
Discussion started by: sanzee007
3 Replies

2. Shell Programming and Scripting

Replace directory paths in multiple files at once

I need to update about 2400 files in a directory subtree, with a new directory path inside the files I need to change this occurence in all files: /d2/R12AB/VIS/apps/tech_st/10.1.2 with this: /u01/PROD/apps/apps_st/10.1.3 I know how to change single words using "find . -type f -print0 |... (6 Replies)
Discussion started by: wicus
6 Replies

3. Shell Programming and Scripting

Awk to replace directory paths

Hi all, I have written a bash script to do a few things for my Splunk deployment, however, I am currently stuck on one part... I need to the current working directory (I collect this with `pwd`) in the script as it could in theory be run from a number of locations. I'm not that great with... (5 Replies)
Discussion started by: TauntaunHerder
5 Replies

4. Shell Programming and Scripting

find and replace in a directory using an input file

Hi folks, I need help to finish this script please. see below: I have an input file with all the IP address to names formated like so in a txt file addnsr1pri 166.7.3.105 addnsr1sec 166.2.100.22 addnsr2pri 166.2.220.121 addnsr2sec 166.3.68.45... (12 Replies)
Discussion started by: richsark
12 Replies

5. Shell Programming and Scripting

Replace last 2 folder directory string with sed

Hi guys, I´m trying to replace the 2 last folders name in a list of directories with a new string, but I´m don´t know which regex to apply. Directories list: C/my user/documents/games & music C/my user/documents/photos 09-24-2008 C/my user/settings/config ?1_2 * The last folder may have... (11 Replies)
Discussion started by: cgkmal
11 Replies

6. Shell Programming and Scripting

Replace a string in all files under a directory and its subdirectories

Hello Friends, I've been trying to write a script which finds a string and change it with another string. For this i want to search all files (with its arguments) under a spesific directory and its subdirectories. For example lets assume i want to replace an IP= 192.168.0.4 with another... (4 Replies)
Discussion started by: EAGL€
4 Replies

7. Shell Programming and Scripting

how to do search and replace on text files in directory

I was google searching and found Perl as a command line utility tool This almost solves my problem: find . | xargs perl -p -i.old -e 's/oldstring/newstring/g' I think this would create a new file for every file in my directory tree. Most of my files will not contain oldstring and I... (1 Reply)
Discussion started by: siegfried
1 Replies

8. Shell Programming and Scripting

find and replace string in a directory files

Hi, I have a directory has DIR1 and the D1 directory has 200+ files. I want change the string from "Bangalore" to "Bangaluru" in all files in the D1 directory. Thanks (2 Replies)
Discussion started by: koti_rama
2 Replies

9. Shell Programming and Scripting

Replace a Directory path with another in a file

Hi, I have abt 20-30 scripts using a directory structure. I have to replace a directory structure in a file for example "/i01/proc" with "/dwftp/scripts" using sed. The command :- cat filename | sed 's/"i01/proc"/"dwftp/scripts"' is not working. Can someone help me in this regard? ... (3 Replies)
Discussion started by: venkatajay_18
3 Replies

10. Shell Programming and Scripting

Replace characters in all file names in a particular directory

Hi, I have searched the forum on how to mass replace the file names. We are doing the migration and I am trying to accomplish a task where I have to replace all UNIX scripts in a particular directory that start with bdw to fdm... For example: bdw0110137.sh should be fdm0110137.sh Keep the... (4 Replies)
Discussion started by: madhunk
4 Replies
Login or Register to Ask a Question