Skip to main content
2 of 5
edited tags
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264

awk referring to an array element

#!/usr/bin/env bash
awk `
  BEGIN {
    arr[A]=1;
    arr[B]=1;
    arr[C]=1;
    arr[E]=1;
    arr[J]=8;
    arr[Q]=10;
    print arr[J]
  }`

the above command outputs the latest set value for arr['subscript'], in this case 10 that is value of arr[Q] just before print and not 8 that is the value of arr[J].

Also I want to be able to assign in few line command value to all arr['subscript'] that have same value, and not go assigning them values one by one like in the command above.