[英]How can I get the name of a directory with an unknown specific pattern, then cd to it (in bash, on macOS)
I have a lots of subjects, each with a 2 or 3 sub-directories that have the pattern of "subjectname_XXX_aslpp".我有很多主题,每个主题都有 2 或 3 个具有“subjectname_XXX_aslpp”模式的子目录。 The XXX is different between sub-dirs and subjects.子目录和主题之间的 XXX 不同。
I have a large loop that goes through each subject, but I need to operate on a specific file in each of the "subjectname_XXX_aslpp" directories, so I need to know its pathname.我有一个遍历每个主题的大循环,但是我需要对每个“subjectname_XXX_aslpp”目录中的特定文件进行操作,所以我需要知道它的路径名。
eg If for subject 1, I have 3 subdirs (changes between subs,), XXX=123, 758, 294, then my loop needs to jump into that subject.例如,如果对于主题 1,我有 3 个子目录(子目录之间的变化),XXX=123、758、294,那么我的循环需要跳转到该主题。 then operate on a file inside each of those folders.然后对每个文件夹中的文件进行操作。
mycommand subject1/subjectname_123_aslpp/diffav_calib.nii.gz
mycommand subject1/subjectname_758_aslpp/diffav_calib.nii.gz
mycommand subject1/subjectname_294_aslpp/diffav_calib.nii.gz
For example例如
MOUNT="/mypath/to/data/"
for subject in $subjectlist
do
for numDir in $howmanysubdirs
do
myfunction ${MOUNT}/${subject}/${subject}_XXX_aslpp/diffav_calib.nii.gz
...
done
done
Any help is much appreciated!任何帮助深表感谢! Thanks谢谢
This seems to be working, thank you!这似乎有效,谢谢! @MaximSagaydachny @MaximSagaydachny
for file in $(find ${MOUNT}/${subject}/ -name 'diffav_calib.nii.gz' );
do
echo $file
tmpPath=$(dirname $file)
echo $tmpPath
flirt -in $file\
-ref ${ANATMOUNT}/${anatsub}.nii\
-out $tmpPath/diffav_calib_flirt\
-omat $tmpPath/diffav_calib_flirt.mat\
-bins 256\
-cost corratio\
-searchrx -90 90\
-searchry -90 90\
-searchrz -90 90\
-dof 12\
-interp trilinear
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.