You don't mention your OS so it's hard to guess what tools may be available to you. I find mmv
simplest for cases like this. It uses shell globs rather than regular expressions:
$ mmv -n 'results_*_*_*_*.txt' 'results_#2_#4_#3_#1.txt'
results_20210503_input003_run017_cluster003.txt -> results_input003_cluster003_run017_20210503.txt
Remove the -n
when you are satisfied with the proposed re-namings.
If you really have to do it "in bash", then
for f in results_*.txt; do
IFS=_ read -a elems <<<"${f%.txt}"
echo mv -n "$f" "results_${elems[2]}_${elems[4]}_${elems[3]}_${elems[1]}.txt"
done
mv -n results_20210503_input003_run017_cluster003.txt results_input003_cluster003_run017_20210503.txt
Remove the echo
to actually rename the files.
rename -n 's/(.+)(_.+)(_.+)(_.+)(_.+)(\.txt)/$1$3$5$4$2$6/'
– TGIBear May 04 '21 at 14:46