Basically, I'm trying to increment each digit in _XtoX of each file below by 20
err_5JUP_N2_UUCCGU_1to2 err_5JUP_N2_UUCCGU_3to4 err_5JUP_N2_UUCCGU_5to6 err_5JUP_N2_UUCCGU_7to8 err_5JUP_N2_UUCCGU_9to10
such that the new file names should look like such:
err_5JUP_N2_UUCCGU_21to22 err_5JUP_N2_UUCCGU_23to24 err_5JUP_N2_UUCCGU_25to26 err_5JUP_N2_UUCCGU_27to28 err_5JUP_N2_UUCCGU_29to30
I came up with the following snippet of code:
for FILE in err*
do
mv $FILE ${FILE/$"_"*to*/"_$((*+20))to$((*+20))}
done
I essentially identified the pattern with "_"*to*/, but I'm pretty sure the * is not a reasonable way to capture the values and increment them. What is an alternative solution to this?
BASH_REMATCH, which is populated by[[ $string =~ $regex ]]. Ensure that all the content you want to reuse unchanged is included in match groups (distinct from the groups collecting content to use as input to calculate new values), and then it's easy to construct a new string from those groups.renamecommand? It can do this pretty easily using theemodifier ins///. This will be much easier than trying to do it usingbashbuilt-ins.