我在排序列表時遇到問題。我認爲它是我把琴絃放在一起的方式。但讓我們看看細節:在bash中排序列表
我有大的(Windows)的TXT文件。這些是自述文件的修補程序。我想這個問題,這是解決了在此版本中,這樣提取的HotFix號碼:
1378 Issue: Here is the issue that is fixed
1390 Issue: Another issue is fixed
1402 Issue: Yet another fixed issue
我有一個循環接一個計算一個文件。在這個循環中,在一些抽取操作之後,我有一個字符串變量用於HotFix-Number,tmp4.txt用於屬於HotFix-Number的文本。
$NR=1378
cat tmp4.txt - Output: Issue: Here is the issue that is fixed
在循環結束時,我把這些2個組件一起:
array[IDX]=$(echo $NR $(cat tmp4.txt));
循環結束後,我檢查了各指標的內容。如果我贊同的單品,我得到正確的形式:
echo ${array[0]} #output: 1390 Issue: Another issue is fixed
echo ${array[1]} #output: 1378 Issue: Here is the issue that is fixed
echo ${array[2]} #output: 1402 Issue: Yet another fixed issue
...
但是,當我想用排序
for j in ${array[@]}; do echo "$j"; done | sort -n >> result.txt;
列表中我得到所有單個的詞進行排序按字母順序排列的文件。但我只想提到HotFix-Number。
# Sampleoutput from result.txt for these 3 examples
Another
another
fixed
fixed
fixed
Here
...
Yet
1378
1390
1402
請更新問題..沒有意義。特別是最後一句話! –
[對多個部分項目排序列表]的可能重複(http://stackoverflow.com/questions/16812914/sorting-a-list-with-multi-part-items) –