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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-16-2006
madhunk madhunk is offline
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
  #2 (permalink)  
Old 02-16-2006
madhunk madhunk is offline
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?
  #3 (permalink)  
Old 02-16-2006
bigearsbilly bigearsbilly is offline
Registered User
  
 

Join Date: Feb 2006
Location: Southern England
Posts: 102
for f in bdw* ;do
echo mv $f fdm${f%bdw}
done
  #4 (permalink)  
Old 02-16-2006
RTM's Avatar
RTM RTM is offline Forum Advisor  
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
  #5 (permalink)  
Old 02-16-2006
bigearsbilly bigearsbilly is offline
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
Sponsored Links
Closed Thread

Bookmarks

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 01:39 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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