I need help with the following:
I have these files with names: ABC.rt1, ABC.rt2, ... , ABC.rt8
I should rename all of them in the following way: if the number, let us say i at the end .rt${i} is odd, then replace the extension by appendig AB, else CD. For example I would expect these output:
ABC.rt1 –> ABC.rt1-AB
ABC.rt2 –> ABC.rt1-CD … etc.
I tried to use this simple script, but does not work:
for i in `seq 1 8`; do mv -v ./ABC.rt${i} ./ABC.rt${if [ $(( $i % 2 )) -eq 0 ] ; then echo ${i}-CD; else echo ${i}-AB;fi};done
Can you help me?
Try:
Don’t try and cram all that in a single line, it’s unreadable and your syntax ends up being incorrect.