The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find and Replace NycUnxer UNIX for Dummies Questions & Answers 4 03-05-2008 09:20 PM
find and replace rakshit Shell Programming and Scripting 4 01-24-2008 12:52 AM
find and replace mahabunta UNIX for Dummies Questions & Answers 7 09-21-2006 09:05 AM
find and replace ram2s2001 Shell Programming and Scripting 2 12-04-2005 11:46 PM
Find & Replace gagansharma Shell Programming and Scripting 3 11-27-2001 01:17 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 06-11-2008
Registered User
 

Join Date: Jun 2008
Posts: 10
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
Reply With Quote
Forum Sponsor
  #2  
Old 06-11-2008
Registered User
 

Join Date: Jul 2005
Location: Oak Park, IL
Posts: 100
Quote:
Originally Posted by cv_pan View Post
I actually want to remove any occurance of C:\Project\ABC\bin in the files.
Got it.

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

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
Reply With Quote
  #3  
Old 06-18-2008
Registered User
 

Join Date: Jun 2008
Posts: 10
mschwage

Thanks a lot!! works as expected

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!
Reply With Quote
  #4  
Old 06-18-2008
Registered User
 

Join Date: Jun 2008
Posts: 10
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?
Reply With Quote
  #5  
Old 06-18-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,196
Quote:
Originally Posted by cv_pan View Post
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 View Post
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:42 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