Computing.Net > Forums > Unix > Modify multiple filename ksh script

Modify multiple filename ksh script

Reply to Message Icon

Original Message
Name: lspvvq
Date: June 27, 2007 at 19:57:25 Pacific
Subject: Modify multiple filename ksh script
OS: UNIX
CPU/Ram: not sure
Model/Manufacturer: not sure
Comment:

I have a folder with a large amount of .mdl and .att files. There are also some with extensions after that .att or .mdl. An example of each:

810i41VicsFinBenT.att
ordoxmlRedmanS.mdl.orig
850i41OwenCorningS.mdl
ordrespRedman.att
ordrespRedmanT.mdl

For the .mdl files, I need to add an 'EG' in front of either the capital 'S' or 'T' that appears before .mdl.

For the .att files, I need to add an 'EG' simply in right before the .att.

How can I write a single script to accomplish this that will work for all the different file names I have? I am on a unix machine using ksh. Thanks.


Report Offensive Message For Removal


Response Number 1
Name: thepubba1
Date: June 28, 2007 at 21:07:24 Pacific
Subject: Modify multiple filename ksh script
Reply: (edit)

#!/bin/ksh
for file in *
do
if [[ $file == *".mdl" ]] || [[ $file == *".att" ]]
then
case $file in
*".att" )
mv $file "${file%%.*}.EG.att"
;;
*"T.mdl" )
mv $file "${file%%.*}.EGT.mdl"
;;
*"S.mdl" )
mv $file "${file%%.*}.EGT.mdl"
;;
esac
fi
done

This will handle the files that end in .att or .mdl. Not sure if you want the .orig files renamed. If so, just ask and I'll post how to do that.


Report Offensive Follow Up For Removal

Response Number 2
Name: lspvvq
Date: July 2, 2007 at 06:01:15 Pacific
Subject: Modify multiple filename ksh script
Reply: (edit)

Ok, so I guess I am a beginner still at scripts because I can't get the script to work. Do I need to make the script a certain type of executable? Should it be a .sh or .exe file?

Do I need to specify the path of the folder to be edited in the script somewhere?

How do I run the script on the cmd line?

Please let me know, Thanks.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Modify multiple filename ksh script

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software