![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shell Script to rename files | yakuzaa | Shell Programming and Scripting | 2 | 03-21-2009 01:33 PM |
| Shell script to rename files with .1,.2,.3 ....ext respectively | satyajit007 | Shell Programming and Scripting | 4 | 02-06-2009 06:43 AM |
| rename multiple filename.45267.txt to >> filename.txt | jason7 | Shell Programming and Scripting | 6 | 01-29-2009 05:37 PM |
| How to Rename/Convert Files in Shell Scripting? | hanu_oracle | Shell Programming and Scripting | 11 | 10-21-2008 10:13 AM |
| rename files using shell scripting | gfhgfnhhn | Shell Programming and Scripting | 4 | 07-04-2006 05:37 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hello~
I'm on AIX version 5 and I believe I have the tcsh shell environment to play in. Can you guys help me with a solution to rename all files that have "eclp" in the filename to "ecl" ? I basically want to rename the files and strip the "p" out. i.e. original filenames: grp_eclp_grp_cent_ADTA.xlt grp_seri_grp_eclp_ADTB.xlt grp_eclp_grp_cern_ADTA.xlt grp_seri_grp_eclp_ADTC.xlt grp_eclp_grp_cern_ADTB.xlt grp_sftmd_grp_eclp_ADT.xlt altered filenames when done: grp_ecl_grp_cent_ADTA.xlt grp_seri_grp_ecl_ADTB.xlt grp_ecl_grp_cern_ADTA.xlt grp_seri_grp_ecl_ADTC.xlt grp_ecl_grp_cern_ADTB.xlt grp_sftmd_grp_ecl_ADT.xlt Thanks in advance! ![]() |
|
||||
|
Kshji,
Thanks for your help. One of team members used the following (can you tell me what the difference is between your method and his?): #!/usr/bin/sh # usage: call ./rename.sh .*.xlt for file in *.xlt do newfile=`echo $file | sed s/$1/$2/g` echo is $newfile mv $file $newfile done |
|
|||||
|
Both are almost perfect .My version use dynamic filenames, your teams dynamic replace rule. Your team version not chech, is there name change or not. My version check it. So this is the best: Code:
#!/bin/sh
#rename.sh
# arg1=old string
# arg2=new string
# arg3-n = files to make name editing
old="$1"
new="$2"
# remove 2 args, rest are filenames
shift 2
for f in $*
do
newname=`echo "$f" | sed "s/$old/$new/" `
if [ "$newname" = "$f" ] ; then
echo "no rename $f"
continue
fi
echo "rename $f -> $newname"
mv "$f" "$newname"
done
Using: Code:
./rename.sh "grp_eclp_" "grp_ecl_" grp*ADTA*.xlt |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|