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
Change All File Names in a Directory andou UNIX for Dummies Questions & Answers 8 01-22-2008 06:06 PM
How to replace characters 7 through 14 of every line in a file jakSun8 Shell Programming and Scripting 9 12-12-2007 11:13 PM
Weird Ascii characters in file names yamsin789 Shell Programming and Scripting 2 10-07-2007 07:27 AM
directory names in a flat file surjyap Shell Programming and Scripting 2 10-06-2005 04:51 AM
File and Directory Names become hidden dbinsol1 UNIX for Advanced & Expert Users 10 05-29-2002 06:58 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-16-2006
Registered User
 

Join Date: Nov 2005
Posts: 91
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 existing script bdw0110137.sh and the contents in it and also have another script fdm0110137.sh with the same contents. Just like copying it into another script but with 'fdm' in the beginning.

I tried using the cut command, and also tried to change the code I found in the forum.

I would appreciate if you could help me in this regard.

Thank You,
Madhu
Reply With Quote
Forum Sponsor
  #2  
Old 02-16-2006
Registered User
 

Join Date: Nov 2005
Posts: 91
Kind of achieved by this

#!/bin/ksh
for e in *;
do mv "$e" "`echo $e | sed -e 's/\bdw/fdm/g'`";
done

But it changed the internal contents of the file too....

Is there a better way to achieve this?
Reply With Quote
  #3  
Old 02-16-2006
Registered User
 

Join Date: Feb 2006
Location: Southern England
Posts: 102
for f in bdw* ;do
echo mv $f fdm${f%bdw}
done
Reply With Quote
  #4  
Old 02-16-2006
RTM's Avatar
RTM RTM is offline
Hog Hunter
 
Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
Code:
#!/bin/csh
# Note - run in proper directory
#
ls -1 fdm* > /tmp/bdw.list
set filelist=`cat /tmp/bdw.list`
foreach x ($filelist)
        set newname=`echo $x|sed 's/fdm/bdw/g'`
        echo $newname
        cp $x $newname
end
Reply With Quote
  #5  
Old 02-16-2006
Registered User
 

Join Date: Feb 2006
Location: Southern England
Posts: 102
oops! slight error should be # not %
Code:
#!/bin/bash

for f in bdw* ;do
        echo mv $f fdm${f#bdw}
done
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 10:52 PM.


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