Contents of folder /home/User/Desktop/DR
dr_subject00001_Z.nii dr_subject00002_Z.nii dr_subject00003_Z.nii
... and so on (increments by 1 up until the number 40)
Contents of folder /home/User/Desktop/rsfMRI
MCU_0001_01 MCU_0001_03 MCU_0002_03
... and so on (these values are random, but they have a RANGE, the 4 digit value can go up to 40 but these values can be repeated (we can have two 0001), and the 2 digits that follow the underscore alternates between 01 and 03).
What I am trying to do is use a match to find the digits "####_##" (4 digits followed by underscore and 2 other digits) from folder rsfMRI and REPLACE and RENAME the "#####" (5 digits in the file name) of DR folder.
So that the output would be
dr_subject0001_01 dr_subject0001_02 dr_subject0002_03
How can I do that?
Edit: There are the same number of files in both folders. I want it to go through the files in each folder in order so that the first file in DR folder matches first file in rsfMRI folder, and so on.