The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Counting the number of occurances of all characters (a-z) in a string rsendhilmani Shell Programming and Scripting 5 08-05-2008 12:10 PM
Replace spaces recursively prvnrk Shell Programming and Scripting 5 08-31-2007 04:37 AM
How to replace the string in unix file? param_it UNIX for Dummies Questions & Answers 5 06-26-2007 09:06 AM
replace a string with content from another file afatguy Shell Programming and Scripting 4 09-14-2006 09:25 PM
replace a string in a file ratan2204 Shell Programming and Scripting 7 05-10-2006 09:40 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1 (permalink)  
Old 04-11-2006
TheMJ TheMJ is offline
Registered User
  
 

Join Date: Apr 2006
Location: Southern California
Posts: 2
Lightbulb Replace all occurances of a string in all file-/foldernames, recursively - SOLVED

I need a script that will replace all occurances of a string in all filenames and foldernames, recursively.

Right now I have this script:
Code:
for f in `find -name *eye*`; do
  echo processing $f
  g=`expr "xxx$f" : 'xxx\(.*\)' | tr 'eye' 'm'`
  mv "$f" "$g"
done
The problem is that tr replaces the characters e and y with m instead of the string "eye".

I adapted this from http://webxadmin.free.fr/article/she...o-lowe-135.php
so I don't really know what the regular expressions in expr are doing.

It is aggravating because I am so close, but I can't get it to work.

Last edited by TheMJ; 04-12-2006 at 01:40 AM.. Reason: added SOLVED to title
  #2 (permalink)  
Old 04-11-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
I had problems getting your script to work but here is one that does:
Code:
for f in `find . -name \*eye\* -print`; do
  echo processing $f
  g=`print "$f" | nawk 'gsub(/eye/,"m")'`
  mv "$f" "$g"
done
"tr" in the script that your link reference is simply changing upper case names to lower case.
  #3 (permalink)  
Old 04-12-2006
TheMJ TheMJ is offline
Registered User
  
 

Join Date: Apr 2006
Location: Southern California
Posts: 2
Great, that script worked perfectly.
Thanks for the quick reply tmarikle.
-TheMJ
Closed Thread

Bookmarks

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0