Hello, very new to this and have to use tcsh (not a choice at the moment).
I need to convert files within sub directories. My foreach loops don't work.
Directories are as follow:
sub-001
--ses-T1
---- anat
--------File.nii
--ses-T2
----anat
-------File.nii
sub-002
and so on.
My script works only for the first sub-001 and does not move on to the second sub-002. It perfectly executes the operation on my .nii file. (3dcopy)
What am I doing wrong with the foreach that should go through all sub-*?
set data_root = /Users/whatever/ever/Scans
# --------------------------------------------------
# get a list of subjects
cd $data_root
set subjects = ( sub-* )
echo $subjects
# --------------------------------------------------
# process all subjects
foreach subj_id ( $subjects )
echo $subj_id
# foreach subj_id get list of sessions
cd $data_root/$subj_id
set session = ( ses-T* )
echo $session
# for all sessions
foreach session_num ( $session )
#move to anat directory
cd $data_root/$subj_id/$session_num/anat
#for all items
foreach item ( * )
#create variable filename with part of file before the "."
set filename = (`echo $item | awk -F '[.]' '{print $1}'`)
#convert nii to AFNI file and run 3dcopy
3dcopy $item $filename
#make a new directory called nii
mkdir $data_root/$subj_id/$session_num/anat/nii
#move all nii.gz files to new directory
mv *.nii.gz $data_root/$subj_id/$session_num/anat/nii
end
end