Hi Rolf and Steve, My OS is MAS OS X 10.5.8 sort --version : sort (GNU coreutils) 5.93 Here is the result of the differents command line. cat all.msf | sort -k 3 -n | head -n 1 | awk '{print $1}' y01_FA cat all.msf | sort -t ' ' -k 2 -n | head -n 1 | awk '{print $1}' y01_FA cat all.msf | sort -k 2 | head -n 1 | awk '{print $1}' y11_FA When I look at the ouptut of sort, my shell orders only the unit number. It doesn't use the decimal part. cat all.msf | sort -k 2 -n y01_FA 2.3574492500 .5149928333 y03_FA 2.7007018333 .6276878333 y04_FA 2.2736573333 .4934251666 y06_FA 2.2188285000 .5140117500 y09_FA 2.4416411666 .5374885000 y10_FA 2.1813674166 .4532854166 y11_FA 2.0237245000 .4157899166 y02_FA 3.0492390833 .7670747500 y05_FA 3.0221233333 .7417060000 y07_FA 3.0134415833 .7737685833 y08_FA 3.0019868333 .7800315000 y12_FA 3.1669953333 .8578153333 It's all good without the -n cat all.msf | sort -k 2 y11_FA 2.0237245000 .4157899166 y10_FA 2.1813674166 .4532854166 y06_FA 2.2188285000 .5140117500 y04_FA 2.2736573333 .4934251666 y01_FA 2.3574492500 .5149928333 y09_FA 2.4416411666 .5374885000 y03_FA 2.7007018333 .6276878333 y08_FA 3.0019868333 .7800315000 y07_FA 3.0134415833 .7737685833 y05_FA 3.0221233333 .7417060000 y02_FA 3.0492390833 .7670747500 y12_FA 3.1669953333 .8578153333 Just to be sure, I check all.msf and it doesn't seem to have any funny characters in it od -c -b all.msf 0000000 y 0 1 _ F A 2 . 3 5 7 4 4 9 2 171 060 061 137 106 101 040 062 056 063 065 067 064 064 071 062 0000020 5 0 0 . 5 1 4 9 9 2 8 3 3 3 \n 065 060 060 040 056 065 061 064 071 071 062 070 063 063 063 012 0000040 y 0 2 _ F A 3 . 0 4 9 2 3 9 0 171 060 062 137 106 101 040 063 056 060 064 071 062 063 071 060 0000060 8 3 3 . 7 6 7 0 7 4 7 5 0 0 \n 070 063 063 040 056 067 066 067 060 067 064 067 065 060 060 012 0000100 y 0 3 _ F A 2 . 7 0 0 7 0 1 8 171 060 063 137 106 101 040 062 056 067 060 060 067 060 061 070 0000120 3 3 3 . 6 2 7 6 8 7 8 3 3 3 \n 063 063 063 040 056 066 062 067 066 070 067 070 063 063 063 012 0000140 y 0 4 _ F A 2 . 2 7 3 6 5 7 3 171 060 064 137 106 101 040 062 056 062 067 063 066 065 067 063 0000160 3 3 3 . 4 9 3 4 2 5 1 6 6 6 \n 063 063 063 040 056 064 071 063 064 062 065 061 066 066 066 012 0000200 y 0 5 _ F A 3 . 0 2 2 1 2 3 3 171 060 065 137 106 101 040 063 056 060 062 062 061 062 063 063 0000220 3 3 3 . 7 4 1 7 0 6 0 0 0 0 \n 063 063 063 040 056 067 064 061 067 060 066 060 060 060 060 012 0000240 y 0 6 _ F A 2 . 2 1 8 8 2 8 5 171 060 066 137 106 101 040 062 056 062 061 070 070 062 070 065 0000260 0 0 0 . 5 1 4 0 1 1 7 5 0 0 \n 060 060 060 040 056 065 061 064 060 061 061 067 065 060 060 012 0000300 y 0 7 _ F A 3 . 0 1 3 4 4 1 5 171 060 067 137 106 101 040 063 056 060 061 063 064 064 061 065 0000320 8 3 3 . 7 7 3 7 6 8 5 8 3 3 \n 070 063 063 040 056 067 067 063 067 066 070 065 070 063 063 012 0000340 y 0 8 _ F A 3 . 0 0 1 9 8 6 8 171 060 070 137 106 101 040 063 056 060 060 061 071 070 066 070 0000360 3 3 3 . 7 8 0 0 3 1 5 0 0 0 \n 063 063 063 040 056 067 070 060 060 063 061 065 060 060 060 012 0000400 y 0 9 _ F A 2 . 4 4 1 6 4 1 1 171 060 071 137 106 101 040 062 056 064 064 061 066 064 061 061 0000420 6 6 6 . 5 3 7 4 8 8 5 0 0 0 \n 066 066 066 040 056 065 063 067 064 070 070 065 060 060 060 012 0000440 y 1 0 _ F A 2 . 1 8 1 3 6 7 4 171 061 060 137 106 101 040 062 056 061 070 061 063 066 067 064 0000460 1 6 6 . 4 5 3 2 8 5 4 1 6 6 \n 061 066 066 040 056 064 065 063 062 070 065 064 061 066 066 012 0000500 y 1 1 _ F A 2 . 0 2 3 7 2 4 5 171 061 061 137 106 101 040 062 056 060 062 063 067 062 064 065 0000520 0 0 0 . 4 1 5 7 8 9 9 1 6 6 \n 060 060 060 040 056 064 061 065 067 070 071 071 061 066 066 012 0000540 y 1 2 _ F A 3 . 1 6 6 9 9 5 3 171 061 062 137 106 101 040 063 056 061 066 066 071 071 065 063 0000560 3 3 3 . 8 5 7 8 1 5 3 3 3 3 \n 063 063 063 040 056 070 065 067 070 061 065 063 063 063 063 012 0000600 sort with the -n option seems to not worked properly on my system. I'm puzzled. Sincerly, Christophe On Sun, Feb 26, 2012 at 12:40, Rolf A. Heckemann < [log in to unmask]> wrote: > 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 >