Use array variable in awk?

后端 未结 4 922
你的背包
你的背包 2020-12-06 02:55
A=(aaa bbb ccc)    
cat abc.txt | awk \'{ print $1, ${A[$1]} }\'

I want to index an array element based on the $1, but the code above is not correc

4条回答
  •  执念已碎
    2020-12-06 03:07

    If you are going to be hard-coding the A array, you can just initialize it in awk

    awk 'BEGIN{A[0]="aaa";A[1]="bbb"}{ print $1, A[$1] }' abc.txt
    

提交回复
热议问题