I have multiple Freesurfer exports with subdirectories named "stats" in each one. I want to run a bash script that searches for each "stats" folder then CDs in to it, runs a predefined perl script that converts specified stats files contained in each folder. I want them to run on each folder recursively. The stats folders are named with the MRI number then the date.
I was able to get the script to separate the MRIDATE, MIRIID and create files from inside the subfolder of one of the Exports. I cannot get it to work a subdirectory below.
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
for D in */*/*/stats/; do
echo $D
if [ -d "${D}" ]; then
cd "${D}"
cwd=$(pwd)
D2=$(dirname "$cwd")
#Capture second folder in MRI name and date
MRINAME=$(basename "$D2")
DIRNAME2=$(basename "$D2")/$(basename "$cwd")
MRIID="$(cut -d'_' -f1 <<<"$MRINAME")"
echo "$MRIID"
MRIDATE="$(cut -d'_' -f2 <<<"$MRINAME")"
echo "$MRIDATE"
/Users/xxxxx/Documents/Bitbucket\ Repository/conversion-scripts/mri-read.pl -d $MRIDATE -s $MRIID lh.aparc.stats rh.aparc.stats wmparc.stats aseg.stats
fi
done