??????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??娲�?????????????椤wk???????????????????????????? ?纾琣rray[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????????????????????????谩?