??????awk???????????????????????????????????awk????????Щ??????????????????????????????????????Щ?????????????????????????????????? awk ?????????????????(associative arrays)??????±???????????????????awk ?е????鯔??????????????????????С??????????? 0 ????????????????????????????????磺
??????????巽??
????1?????????????????????(?±?)
????Tarray[1]=“cheng mo”
????Tarray[2]=“800927”
????2???????????????????????(?±?)
????Tarray[“first”]=“cheng ”
????Tarray[“last”]=”mo”
????Tarray[“birth”]=”800927”
????????? print Tarray[1] ?????”cheng mo” ?? print Tarray[2] ?? print[“birth”] ??????? ”800927” ??
???????????????????
????[chengmo@localhost ~]$ awk --version
????GNU Awk 3.1.5
??????e汾???3.1?????????汾???溯??????????
??????????鳤???length????????
????[chengmo@localhost ~]$ awk 'BEGIN{info="it is a test";lens=split(info??tA??" ");print length(tA)??lens;}'
????4 4
????length???????????????鳤???split???з???????????飬????????????鳤???
????(asort????:
????[chengmo@localhost ~]$ awk 'BEGIN{info="it is a test";split(info??tA??" ");print asort(tA);}'
????asort????????????????????鳤???
???????????????(???????????????
????[chengmo@localhost ~]$ awk 'BEGIN{info="it is a test";split(info??tA??" ");for(k in tA){print k??tA[k];}}'
????4 test
????1 it
????2 is
????3 a
????for…in ????????????????????飬??????????????????for…in ?????????????顣????????????????飬???????±??á?
????[chengmo@localhost ~]$ awk 'BEGIN{info="it is a test";tlen=split(info??tA??" ");for(k=1;k<=tlen;k++){print k??tA[k];}}'
????1 it
????2 is
????3 a
????4 test
????????????±????1???????c???鯔?????
?????ж??????????????????
?????????????ж??????
????[chengmo@localhost ~]$ awk 'BEGIN{tB["a"]="a1";tB["b"]="b1";if(tB["c"]!="1"){print "no found";};for(k in tB){print k??tB[k];}}'
????no found
????a a1
????b b1
????c
??????????????????tB[“c”]??ж??壬?????????????????????ü???????????????????????awk????????????飬?????????????????key?????????????????.
????????ж??????
????[chengmo@localhost ~]$ awk ‘BEGIN{tB["a"]=”a1″;tB["b"]=”b1″;if( “c” in tB){print “ok”;};for(k in tB){print k??tB[k];}}’
????a a1
????b b1
????if(key in array) ???????????ж?????????????”key”?????
????????????
????[chengmo@localhost ~]$ awk 'BEGIN{tB["a"]="a1";tB["b"]="b1";delete tB["a"];for(k in tB){print k??tB[k];}}'
????b b1
????delete array[key]????????????????key??????????
??????????????????(???????????
????awk??????????????????????飬????????awk??洢?????????????顣awk???????????????????????????? ?磬array[2??4] = 1?????????????????awk????????????????SUBSEP (34)????????Σ?????????????У?????????array?洢???????????2344??
??????????????????????????????????? if ( (i??j) in array)???????????????±???????????????С?
????????????????????????????????? for ( item in array )???????????????顣???????鯔???????????????????split()????????????????±??????
split ( item?? subscr?? SUBSEP)
[chengmo@localhost ~]$ awk 'BEGIN{
for(i=1;i<=9;i++)
{
for(j=1;j<=9;j++)
{
tarr[i??j]=i*j;
print i??"*"??j??"="??tarr[i??j];
}
}
}'
1 * 1 = 1
1 * 2 = 2
1 * 3 = 3
1 * 4 = 4
1 * 5 = 5
1 * 6 = 6
……
???????????array[k??k2]??????????????.
????????????
[chengmo@localhost ~]$ awk 'BEGIN{
for(i=1;i<=9;i++)
{
for(j=1;j<=9;j++)
{
tarr[i??j]=i*j;
}
}
for(m in tarr)
{
split(m??tarr2??SUBSEP);
print tarr2[1]??"*"??tarr2[2]??"="??tarr[m];
}
}'
??????????awk????????????????????????á?