To find and replace paths consisting \


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To find and replace paths consisting \
# 1  
Old 06-11-2008
To find and replace paths consisting \

Hi all,
I am new to unix and wanted to replace the string consisting \ with nothing.

I tried the following but did not help.

for y in `ls DIV*`;
do
sed s/C:\\Project\\AML\\bin//g $y > temp
mv temp $y
done

I actually want to remove any occurance of C:\Project\ABC\bin in the files.

Thanks & Regards
# 2  
Old 06-11-2008
Quote:
Originally Posted by cv_pan
I actually want to remove any occurance of C:\Project\ABC\bin in the files.
Got it.

Quote:
Originally Posted by cv_pan
Hi all,
I am new to unix and wanted to replace the string consisting \ with nothing.
No you don't... Smilie

Anyway, all wisecracks aside, you're actually pretty close. Here's your solution:

Code:
for y in `ls DIV*`
do
       temp=`echo $y | sed -e 's/C:\\Project\\AML\\bin//g'`
       mv $temp $y
done

# 3  
Old 06-18-2008
mschwage

Thanks a lot!! works as expected Smilie

however, could you please elaborate on -e option..

-e Script
"Uses the Script variable as the editing script. If you are using just one -e flag and no -f flag, the -e flag can be omitted."

I do not understand it competely.. Thanks in advance!
# 4  
Old 06-18-2008
for y in `ls DIV*`
do
sed -e 's/C:\\Project\\AML\\bin//g' $y > temp
mv temp $y
done

I had to do this instead as I kept getting the error sayng both $temp & $y are identical.. is something wrong?
# 5  
Old 06-18-2008
Quote:
Originally Posted by cv_pan
however, could you please elaborate on -e option..
The -e option isn't necessary here, it's for combining multiple commands.

Quote:
Originally Posted by cv_pan
I had to do this instead as I kept getting the error sayng both $temp & $y are identical.. is something wrong?

Place the mv command after the loop.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove leading dot and slash on relative paths with find

When I specify a directory by name the leading ./ is not shown: $ find somedir/ somedir/a.bin somedir/target/out.binBut when I specify current dir it adds the ./ to the beginning of each result: $ find . | grep somedir ./somedir/a.bin ./somedir/target/out.binIs there any particular reason why... (2 Replies)
Discussion started by: Tribe
2 Replies

2. UNIX Desktop Questions & Answers

Change name of files to their paths -- find loop

Dear All, I have many sub-folders but each of them have a file with same name but different data. I want to either move or copy them into a new folder but they need to have the path of where they are coming as part of their name... I have managed to find the files but dont know how to change... (2 Replies)
Discussion started by: A-V
2 Replies

3. Shell Programming and Scripting

Solaris FIND: Exclude Specific Paths

Using Sol 10 + KSH. I need to run a find command on the whole system "/" and exclude a bunch of explicit directories and files that may or may not be on each system. I cannot use the -name because i dont want to exclude all dirs named just specific paths. -path/-wholename is not an option... (2 Replies)
Discussion started by: nitrobass24
2 Replies

4. 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

5. Programming

Can't find paths.h

I wasn't sure which forum to post this in. I am trying to compile logsurfer. After I run configure and the make, I get a complaint that paths.h is not found. I see three places where there is a paths.h: /usr/include/pgsql/server/optimizer/paths.h... (3 Replies)
Discussion started by: brownwrap
3 Replies

6. 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

7. Shell Programming and Scripting

Find text containing paths and replace with a string in all the python files

I have 100+ python files in a single directory. I need to replace a specific path occurrence with a variable name. Following are the find and the replace strings: Findstring--"projects\\Debugger\\debugger_dp8051_01\\debugger_dp8051_01.cywrk" Replacestring--self.projpath I tried... (5 Replies)
Discussion started by: noorsam
5 Replies

8. Shell Programming and Scripting

Find Directory from array of file names with paths

I have a script that generates a variable with the location of a file and its complete path. What i want to do is to "cd" to the directory where that file is located using the path name of the file. GIS has absolutely failed me. For example when i run my script it generates a variable called... (1 Reply)
Discussion started by: Knome
1 Replies

9. Solaris

find home directory paths for all users

How to find al the user's home directories? (2 Replies)
Discussion started by: a2156z
2 Replies

10. Shell Programming and Scripting

find multiple paths

How do i find files in more than one directory? I searched through forums, but could not land into the right thread. I tried something like find dir1|dir2 -name file1 but it doesn't work. Please suggest. (5 Replies)
Discussion started by: krishmaths
5 Replies
Login or Register to Ask a Question