0

In my path, I have totally 120 cases, each case has two files, the path looks like this:

00001_FA.nii.gz 
00001_FA_grot.nii.gz
00002_FA.nii.gz  
00002_FA_grot.nii.gz
.. ..
00120_FA.nii.gz  
00120_FA_grot.nii.gz

I want to do fslstats 00001_FA_nii.gz -k 00001_FA_grot.nii.gz -m then repeat the process till the 00120 case.

How to write the command? Thanks

K7AAY
  • 17,202
Yw Liu
  • 1

1 Answers1

3

You need to use a loop function (for, for instance, is pretty helpful). Also, you need to convert 1, 2, 3 .. 119, 120 to a 5-digits format. You can do that thanks to printf.

And there is your script :

for i in {1..120} ; do
  j=$(printf %05d $i)
  fslstats ${j}_FA_nii.gz -k ${j}_FA_grot.nii.gz -m
done

As @steeldriver noted in the comments, bash can now understand leading 0 in braces, so you can substitute

for i in {1..120} ; do
  j=$(printf %05d $i)

with for j in {00001..00120} ; do