本文主要是介绍awk-数组-待续,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一维数组的使用极其常用操作:
访问,排序,去重
eg:
awk '
BEGIN{
info="it is a test aha ha ha ha. test over";
lens=split(info,tA," ");#split
print "len of Arr:"
print length(tA),lens;
print asort(tA);#sort ,return len
print "print Arr disorder: "
for(i in tA)#show as dis order
print i,tA[i]
print "print tA in order:"
len = asort(tA,arr)
for(i=1;i<=len;i++)
print i,arr[i]
print "delete a in tA "
for(i in tA){
if ( tA[i] == "a")
delete tA[i]
}
for(i in tA){
print i,tA[i]
}
print "delte duplicate:"
for(i in tA){
if(!a[tA[i]]++)
print i,tA[i]
}
print "print tA in desc order"
for(i in tA)
print i, tA[i] | "sort -r -n -k2"
}'
多维数组的使用:
本质为一维数组,[i,j]形式存储。默认分隔符为\034。
这篇关于awk-数组-待续的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!