How can I change following file name in a bash script?
From file names:
myfile-module-1.0-3.0.el6.x86_64.package
To file names:
myfile-module1_0-1.0-3.0.el6.x86_64.package
^ ^ ^ ^ ^ ^ ^ ^
Basically, the digit 1.0 is a version number, the digit 3.0 is a release number, I need to add the version number to module name and change the version number "." to "_". So the module name "module" becomes "module1_0", the rest are identical.
Brilliant, that works well. The only thing I forgot to mention was that the version number could be 2 digits 1.0, or 3 digits 1.1.1, or 4 digits 1.2.1.1. Can it be adapted to different digits of version numbers?
I believe bipinijith was on the right track, but didn't quite follow through with what was requested. This uses a shell expansion that is not defined by the standards, but is available in recent versions of both ksh and bash:
for i in *-module-*
do echo mv $i ${i/-module-/-module1_0-}
done
Remove the echo after verifying that the mv commands it will print do what you want to have done.
But you hardcoded version 1.0 in there. What if it's 2.3.4? Although the parameter expansion supports nested vars, like ${i/foo/${bar}} , you have to grab the version somehow.