Aside from all the reasons scripts shouldn't be written in csh
, you are mixing bash syntax and csh syntax in your script.
You're starting your loop with the csh
foreach
and trying to finish them with the bash
done
. The loop exit for a csh
foreach
is end
, not done
. Also, you have a variable VISIT
that you are calling $VIS
in your grep statement.
So you script would be syntactically correct in csh with:
#!/bin/csh
foreach SUB (1 2 3 4 5 6 7 8 9 10 11 12 13 14)
echo $SUB
foreach VISIT (1 2 3 4 5 6 7 8)
echo $VISIT
grep 'StudyDate' -f /home/colourlab/Desktop/DrummingDTI/D${SUB}/D${SUB}V${VISIT}/scout/001/infodump.dat
end
end
or in bash:
#!/bin/bash
for SUB in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do
echo $SUB
for VISIT in 1 2 3 4 5 6 7 8; do
echo $VISIT
grep 'StudyDate' -f /home/colourlab/Desktop/DrummingDTI/D${SUB}/D${SUB}V${VISIT}/scout/001/infodump.dat
done
done
EDIT 2017/04/03
Here's a version of the bash script that adds a test for the file:
#!/bin/bash
idf_pfx="/home/colourlab/Desktop/DrummingDTI"
idf_sfx="scout/001/infodump.dat"
for SUB in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do
echo $SUB
for VISIT in 1 2 3 4 5 6 7 8; do
echo $VISIT
idfile="${idf_pfx}/D${SUB}/D${SUB}V${VISIT}/${idf_sfx}"
if [ -f "${idfile}" ]; then
grep 'StudyDate' $idfile
else
echo "No studydate file: $idfile"
fi
done
done