I have multiple directories with unique identifying names. Within each of these are further identicle subdirectories generated by an automated analysis software. Within one of these subdirectories is a file I want to pick out and move to a unique dir, naming them after their respective parent directory.
Directories = A001 A002 A003 A004
Subdirectories = A001/files A002/files A003/files A004/files
Identical file name in each subdirectory = A001/files/aseg.mgz A002/files/aseg.mgz etc etc
Unique new directory = collated_aseg
I want to move all the aseg.mgz files into the collated_aseg dir and rename them so they are identifiable as coming from the original parent directory: e.g. A001_aseg.mgz (or equivalent).
I have looked at similar issues (Rename a file to parent directory's name in terminal) - however, these have only one layer of directory, whereas my issue has two. I was wondering whether this could be easily done.