In my case I have a group of files which needs to be renamed before I can work with them. Each file has its own role in group and has its own pattern.
As result I have a list of rename commands like this:
f=`ls *canctn[0-9]*` ; mv $f CNLC.$f
f=`ls *acustb[0-9]*` ; mv $f CATB.$f
f=`ls *accusgtb[0-9]*` ; mv $f CATB.$f
f=`ls *acus[0-9]*` ; mv $f CAUS.$f
Try this also :
f=MyFileName; mv $f {pref1,pref2}$f{suf1,suf2}
This will produce all combinations with prefixes and suffixes:
pref1.MyFileName.suf1
...
pref2.MyFileName.suf2
Another way to solve same problem is to create mapping array and add corespondent prefix for each file type as shown below:
#!/bin/bash
unset masks
typeset -A masks
masks[ip[0-9]]=ip
masks[iaf_usg[0-9]]=ip_usg
masks[ipusg[0-9]]=ip_usg
...
for fileMask in ${!masks[*]};
do
registryEntry="${masks[$fileMask]}";
fileName=*${fileMask}*
[ -e ${fileName} ] && mv ${fileName} ${registryEntry}.${fileName}
done