如何e.g. ( "A: 2" "B: 3" "C: 1" )
按值对 bash 中的“python 字典样式”数组进行排序?我认为,此代码段将使我的问题更加清楚。
State="Total 4 0 1 1 2 0 0"
W=$(echo $State | awk '{print $3}')
C=$(echo $State | awk '{print $4}')
U=$(echo $State | awk '{print $5}')
M=$(echo $State | awk '{print $6}')
WCUM=( "Owner: $W;" "Claimed: $C;" "Unclaimed: $U;" "Matched: $M" )
echo ${WCUM[@]}
这将简单地打印数组:Owner: 0; Claimed: 1; Unclaimed: 1; Matched: 2
如何对数组(或输出)进行排序,消除任何具有“0”值的对,使结果如下:
Matched: 2; Claimed: 1; Unclaimed: 1
提前感谢您的任何帮助或建议。干杯!!