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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Modify multiple filename ksh script

Reply to Message Icon

Name: lspvvq
Date: June 27, 2007 at 19:57:25 Pacific
OS: UNIX
CPU/Ram: not sure
Product: 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.



Sponsored Link
Ads by Google

Response Number 1
Name: thepubba1
Date: June 28, 2007 at 21:07:24 Pacific
Reply:

#!/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.


0

Response Number 2
Name: lspvvq
Date: July 2, 2007 at 06:01:15 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


tar to cd and or flash dr... Supressing error message



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Modify multiple filename ksh script

Can someone help wid KSH script err www.computing.net/answers/unix/can-someone-help-wid-ksh-script-err/8021.html

ksh script www.computing.net/answers/unix/ksh-script/6748.html

multiple filename as argument www.computing.net/answers/unix/multiple-filename-as-argument/6253.html