Hi,
Let's give me an untested shot:
slst=" 105 167 199"
# if increasing numbers you could use for example:
# slst=$(seq 105 115)
cnt=0
for csj in $slst
do
if [ $cnt -eq 0 ]
then
imcp ${csj}_file newfile
else
fslmaths newfile -add ${csj}_file newfile
fi
cnt=$(($cnt+1))
done
In your syntax, if spaces are not a problem, you would increase the
subject number by one, since the variable j holds the subject number,
and is not a counter or index. Thus you would get 10000, 10446 , 10743.
I added above a counter variable (cnt).
Indexing with bash is possible, but you need to declare an variable as
array, and use then a zero based index. In you case I think this is not
necessary, hence I do not go into much detail here.
I hope I was able to help,
wolf
On 12/23/13, 8:35 PM, Dana Wagshal wrote:
> Hi FSL group,
>
> Sorry for the basic question. I would like to use fslmaths and the -add flag to create a new file. My problem is that the files start with the subject number. Ex- 100_file.nii.gz, 105_file.nii.gz, 167_file.nii.gz, etc. Instead of manually inserting the files by hand (ex- fslmaths 100_file.nii.gz -add 105_file.nii.gz -add 167_file.nii.gz -add ... new_file.nii.gz), is there a way for me to script this, especially in using a large dataset?
>
> I tried the syntax below but it failed to run and I still don't think that it's getting to what I really would like to do without manually inserting the different file names:
>
> SUBJECTS='10000 10445 10741'
> for j in $SUBJECTS; do
>
> fslmaths ${j}_fdt_paths_WM.nii.gz -add $((j + 1))_fdt_paths_WM.nii.gz -add $((j + 2))_fdt_paths_WM.nii.gz new_file.nii.gz
>
> Happy Holidays!!
> Dana
|