Hi Christophe
The -n option to sort ensures numeric ordering (default is
alphabetic). -k 2 specifies that you want to sort on the second field
(key). The default field separator is a blank-to-nonblank-character
transition (at least for the sort found in GNU coreutils). I suspect
that your shell regards the understroke as a blank character.
Therefore, your command tries to numerically sort a series of
identical character strings ("FA"), so it gives up and returns the
original ordering. If my suspicion is correct, each of the following
should give you the result you want:
cat all.msf | sort -k 3 -n | head -n 1 | awk '{print $1}'
# specifies the correct field (key) on which to sort
cat all.msf | sort -t ' ' -k 2 -n | head -n 1 | awk '{print $1}'
# tells sort to use space as the field separator
# (recommended if you generally have space-separated
# values in your files)
cat all.msf | sort -k 2 | head -n 1 | awk '{print $1}'
# (the one you found to work correctly)
# because when you sort alphabetically, it sorts on the entire
# string from the specified key to the end of the line, so it
# does not matter that each string starts with "FA".
Hope that helps
Rolf
On 24 February 2012 22:28, Christophe Bedetti
<[log in to unmask]> wrote:
> Hi FSL list,
>
> I was looking at the way the best target image is chosen during the step
> tbss_3_postreg when I use the -n option during the step tbss_2_reg.
> Here is my all.msf.
>
> cat all.msf
> y01_FA 2.3574492500 .5149928333
> y02_FA 3.0492390833 .7670747500
> y03_FA 2.7007018333 .6276878333
> y04_FA 2.2736573333 .4934251666
> y05_FA 3.0221233333 .7417060000
> y06_FA 2.2188285000 .5140117500
> y07_FA 3.0134415833 .7737685833
> y08_FA 3.0019868333 .7800315000
> y09_FA 2.4416411666 .5374885000
> y10_FA 2.1813674166 .4532854166
> y11_FA 2.0237245000 .4157899166
> y12_FA 3.1669953333 .8578153333
>
> cat all.msf | sort -k 2 -n | head -n 1 | awk '{print $1}'
> y01_FA
>
> Shouldn't be y11_FA the best image in my case?
> After searching a bit, I found that without the -n option of sort, the
> output is y11_FA.
>
> cat all.msf | sort -k 2 | head -n 1 | awk '{print $1}'
> y11_FA
>
> I'm not sure why.
> I don't understand what is the -n option here.
> Maybe the names of my subjects interfere with sort?
>
> Sincerly,
>
> Christophe
>
--
Rolf A Heckemann, MD PhD
Médecin chercheur
Fondation Neurodis
CERMEP - Imagerie du Vivant
Hôpital Neurologique Pierre Wertheimer
59 Boulevard Pinel
69003 Lyon
France
|