![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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
|
|||
|
|||
|
for f in bdw* ;do
echo mv $f fdm${f%bdw} done |
|
#4
|
||||
|
||||
|
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
|
|||
|
|||
|
oops! slight error should be # not %
Code:
#!/bin/bash
for f in bdw* ;do
echo mv $f fdm${f#bdw}
done
|
|||
| Google The UNIX and Linux Forums |