I need some help with bash script about rename directory:
I want to rename six directories first in order to conduct analysis:
this is original directory name for rename:
MCIA-1-control_20170509
MCIA-2-control_20170509
MCIA-03-timesport_20170717
MCIA-04-timesport_20170717
MCIA-05-timesport_20170717
MCAI-6-timesport_20170717
I need to rename as following:
subj-1-control
subj-2-control
subj-3-timesport
subj-4-timesport
subj-5-timesport
subj-6-timesport
I already declared several variables as below:
$fnIDs #e.g.MCIA-1-control_20170509...
$ren ##e.g. 1-control...
then I run this loop, but the results did not as my expect:
for fn in ${fnIDs}; do
echo "+++this is all folder name for rename: fnIDs:${fnIDs}+++"
echo "+++renameing folder: fn:${fn}+++"
for rn in ${ren}; do
echo "=======ADD "subj" to rename the subj folder==========="
refn=subj-"$rn" #e.g. subj-1-control...
echo "refn:$refn"
echo "rename folder $fn to $refn"
if ( test -d "$raw_dir"/"$fn"); then #if dir exist then
cp -R "$raw_dir"/"$fn" "$raw_dir"/"$refn" #copy and rename file
echo "cp rename the subj folder:$raw_dir/$refn"
elif ( test -d "$raw_dir"/"$refn");then
echo "++++++renamed subject folder already exists+++++++"
#continue
else
echo "+++++somthing went wrong!Name of subject folder does not exists check "$fn $refn"+++++++++"
exit
fi
done
done
when I execute above script, they doing things as below:
+++renameing folder: fn:MCIA-1-control_20170509+++
=======rename the subj folder===========
renfn:subj-1-control
rename folder MCIA-1-control_20170509 to subj-1-control
rename folder MCIA-1-control_20170509 to subj-2-control
What I want to do is:
rename folder MCIA-1-control_20170509 to subj-1-control
rename folder MCIA-2-control_20170509 to subj-2-control...
Basically, it rename original folder name into six different subj folder name... I got stuck here for a while...
Thanks for help me out...
Aucun commentaire:
Enregistrer un commentaire