Sample Header Ad - 728x90

Create folders with unique names of filenames

2 votes
2 answers
774 views
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
Asked by Relyativist (139 rep)
Mar 17, 2020, 03:54 PM
Last activity: Feb 20, 2025, 12:06 PM