例:
test01 aaa
test02 bbb
test06 fff
test03 ccc
test04 ddd
test05 eee
-----------------------------------------
awk '{
oldarr[substr($1,4)]=$2} //老数组为:oldarr[t01]=aaa,oldarr[t02]=bbb...
END
{asort(oldarr, newarr); //将老数组数值排序处理后赋给新数组,新数组为:newarr[1]=aaa,oldarr[2]=bbb...
for(i=1;i<=length(newarr);i++) //asort(oldarr, newarr)自身等于数组长度=6
{printf newarr[i]" "}}' //数组是从1开始的,非0
输出结果为:
aaa bbb ccc ddd eee fff
-----------------------------------------
awk '{
oldarr[substr($1,4)]=$2} //老数组为:oldarr[t01]=aaa,oldarr[t02]=bbb...
END
{asorti(oldarr, newarr); //将老数组下标排序处理后赋给新数组,新数组为:newarr[1]=t01,oldarr[2]=t02...
for(i=1;i<=length(newarr);i++) //length()=asort(oldarr, newarr)=asorti(oldarr, newarr)=6
{printf newarr[i]" "}}'
输出结果为:
t01 t02 t03 t04 t05 t06