I am trying to create folders from unique filenames. Here are the files:
T001
└── 20000101
├── 6_3D-MP-RAGE_97.dcm
├── 6_3D-MP-RAGE_98.dcm
├── 5_133_VOLUMES_99027.dcm
├── 5_133_VOLUMES_99028.dcm
├── 5_133_VOLUMES_99029.dcm
├── 5_133_VOLUMES_99030.dcm
├── 4_COR_3D_T1_MPR_1.dcm
├── 4_COR_3D_T1_MPR_107.dcm
I want bash magic to result in this:
T001
└── 20000101
├── 6_3D
├── 6_3D-MP-RAGE_97.dcm
├── 6_3D-MP-RAGE_98.dcm
├── 5_133
├── 5_133_VOLUMES_99027.dcm
├── 5_133_VOLUMES_99028.dcm
├── 5_133_VOLUMES_99029.dcm
├── 5_133_VOLUMES_99030.dcm
├── 4_COR
├── 4_COR_3D_T1_MPR_1.dcm
├── 4_COR_3D_T1_MPR_107.dcm
And I have tried this code to extract folder names, but got stuck:
all_patterns=()
for file in sorted/folder/*/*
do
name=${file##*/}
pattern=`echo ${name} | cut -f1 -d '_'`
all_patterns+=( "$pattern" )
done
-
,_
,...)?-
,_
)