#!/bin/bash proj_dir=~/dss/msense/stress_and_distractibility # get subdirectories from folder proj_dir/rawdata/asd/ sub_dirs=($(ls -d $proj_dir/rawdata/td/sub-*)) # loop through subdirectories for sub_dir in ${sub_dirs[@]}; do # get subject id from subdirectory sub_id=$(basename $sub_dir) # get the final three letters of the subject id sub_id=${sub_id: -3} # create output directory new_dir=${proj_dir}/sub-TD${sub_id} # if the output directory does not exist, create it if [ ! -d $new_dir ]; then mkdir -p $new_dir fi beh_dir=${new_dir}/beh if [ ! -d $beh_dir ]; then mkdir -p $beh_dir fi # move the hdf files to the output directory mv $sub_dir/*.hdf5 $beh_dir #echo $sub_dir #echo $beh_dir # copy csv files to the output directory cp $sub_dir/*csv $beh_dir done