Hi Meg,
For what I think you want to do I would use the following bash script:
for n in `cat mask` ; do
base=`echo $n | sed 's/.\{7\}$//'
for ff in `ls *_thr0point95.nii.gz` ; do
ffbase=`echo $ff | sed 's/_thr0point95.*$//'`
fslmaths ${ffbase}_thr0point95.nii.gz -mas $n ${ffbase}_thr0point95_${base}
end
end
The previous suggestion will fail because the wildmask (?) is matching multiple images, and so the fslmaths command ends up with a list of images at the start, which is why you see the error. If I'm interpreting your question correctly, you need this kind of double loop to make sure that it processes each image in the *_thr0point95 list separately.
Also, I've left in the bit that removes the last 7 character from the mask filename (forming "base") although if you are just doing it to remove the ".nii.gz" from the filename, then the following is neater (and more general, as it would still work on uncompressed niftis):
base=`$FSLDIR/bin/remove_ext $n`;
All the best,
Mark
On 7 Oct 2013, at 00:15, Meghan McIlwain <[log in to unmask]> wrote:
> Hi Sahar,
>
> Thanks for that. With the script below, it seems to loop through the images but produces no outputs and I'm still getting this error message:
>
> fslmaths temp_FAt3_?_tfce_thr0point95.nii.gz -mas PostThalamicRadLeft.nii.gz temp_FAt3_?_tfce_thr0point95_PostThalamicRadLeft
>
> Error in command line: unknown option "temp_FAt3_2_tfce_thr0point95.nii.gz"
>
> Again, I really appreciate your help with this.
>
> Meg
>
>
>
>
> Hi Meghan,
> My mistake ,sorry.
> Instead of fslmath type falmaths.
>
>
> #!/bin/bash
> for N in $(cat mask)
> do
> BASE=$(echo $N | sed 's/.\{7\}$//g')
> echo "fslmaths temp_FAt3_?_tfce_thr0point95.nii.gz -mas $N temp_FAt3_?_tfce_thr0point95_${BASE}"
> fslmaths temp_FAt3_?_tfce_thr0point95.nii.gz -mas $N temp_FAt3_?_tfce_thr0point95_${BASE}
>
> done
>
>
> echo will print the line in advance and will help you to trigger the error.
> Regards
> Sahar
>
>
>
>
>
> On Sat, Oct 5, 2013 at 7:55 PM, Meghan McIlwain <[log in to unmask]> wrote:
>
> Thanks, Sahar. I think it's almost there... Here's the error message I get now:
>
> Error in command line: unknown option "temp_FAt3_2_tfce_thr0point95.nii.gz"
|