2014-09-26 51 views
0

數組我有一個數組路徑未排序排序在TCL

path(11,0) = susan susan_s1 0.0 peter peter_i_p1 0.0 peter peter_o_p1 0.0 
path(2,0) = maria maria_s2 0.0 ted ted_i_p2 0.0 ted ted_o_p2 0.0 
path(3,0) = maria maria_s3 0.0 ted ted_i_p3 0.0 ted ted_o_p3 0.0 
path(0,0) = maria maria_s0 0.0 ted ted_i_p0 0.0 ted ted_o_p0 0.0 
path(10,0) = susan susan_s0 0.0 peter peter_i_p0 0.0 peter peter_o_p0 0.0 
path(1,0) = maria maria_s1 0.0 ted ted_i_p1 0.0 ted ted_o_p1 0.0 

如果我用(數組名路徑)lsort,我會得到

path(0,0) = maria maria_s0 0.0 ted ted_i_p0 0.0 ted ted_o_p0 0.0 
path(1,0) = maria maria_s1 0.0 ted ted_i_p1 0.0 ted ted_o_p1 0.0 
path(10,0) = susan susan_s0 0.0 peter peter_i_p0 0.0 peter peter_o_p0 0.0 
path(11,0) = susan susan_s1 0.0 peter peter_i_p1 0.0 peter peter_o_p1 0.0 
path(2,0) = maria maria_s2 0.0 ted ted_i_p2 0.0 ted ted_o_p2 0.0 
path(3,0) = maria maria_s3 0.0 ted ted_i_p3 0.0 ted ted_o_p3 0.0 

但是我想有最後的文件如下:

path(0,0) = maria maria_s0 0.0 ted ted_i_p0 0.0 ted ted_o_p0 0.0 
path(1,0) = maria maria_s1 0.0 ted ted_i_p1 0.0 ted ted_o_p1 0.0 
path(2,0) = maria maria_s2 0.0 ted ted_i_p2 0.0 ted ted_o_p2 0.0 
path(3,0) = maria maria_s3 0.0 ted ted_i_p3 0.0 ted ted_o_p3 0.0 
path(10,0) = susan susan_s0 0.0 peter peter_i_p0 0.0 peter peter_o_p0 0.0 
path(11,0) = susan susan_s1 0.0 peter peter_i_p1 0.0 peter peter_o_p1 0.0 

那麼該怎麼辦呢?

或者a)整理路徑 的索引或具有關鍵字列表(超羣,蘇珊)以獲得最終的文件

THX,瑪利亞

回答

-1

嗯...

path(11,0) = susan susan_s1 0.0 peter peter_i_p1 0.0 peter peter_o_p1 0.0 
path(2,0) = maria maria_s2 0.0 ted ted_i_p2 0.0 ted ted_o_p2 0.0 
path(3,0) = maria maria_s3 0.0 ted ted_i_p3 0.0 ted ted_o_p3 0.0 
path(0,0) = maria maria_s0 0.0 ted ted_i_p0 0.0 ted ted_o_p0 0.0 
path(10,0) = susan susan_s0 0.0 peter peter_i_p0 0.0 peter peter_o_p0 0.0 
path(1,0) = maria maria_s1 0.0 ted ted_i_p1 0.0 ted ted_o_p1 0.0 

是不排序。可能你希望按數字順序查看索引。

path(Number,0) 

then Number is Order!不值!是的,這是一個索引!

路徑始終由Number命令稱爲索引!依賴於輸入順序,顯示順序無論...

我從來沒有聽說過關於排序索引!

2

嘗試將-dictionary選項設置爲lsort

lsort -dictionary [array names path] 
# -> 0,0 1,0 2,0 3,0 10,0 11,0 

文檔:arraylsort

+0

這是一個很好的解決方案,因爲它也將排序後的數字的','作爲附屬關鍵。但是它不會做的是將負數視爲正確,因爲它將'-'作爲分隔符,而不是減號。 (對於很多用途,這並不重要。) – 2014-09-26 07:44:20

+0

@DonalFellows:我總是儘量避免考慮負面的事情。 – 2014-09-26 08:01:07