Store value in array with awk

Hi everybody
I wanna store some values that r in a .txt file in some arrays
for example I have:

32782   28
 32783   02
 32784   01
 32785   29
 32786   25
 32787   25
 32788   00
 32789   25
 32790   02
 32791   29
 32792   23
 32793   01
 32794   28

and I need to save the first column in X [i]and the second one in Y[j].
And how can I refer to this value for example print on screen?
Tnx in advance for your help

Just an example (to be adapted depending on your needs)

$ awk '{X[NR]=$1;Y[NR]=$2}END{print X[2]"\n"Y[10]}' input
32783
29

NR stand for Number of Record since the RS (Record Separator) is the newline character by default, NR here simply refer to the line number.

1 Like

If you are talking shell array, try this. Syntax will vary from shell to shell, this one is bash (index starting at 0):

$ X=($(awk '{print $1}' file))
$ echo ${#X[@]}                            # element count
13
$ echo ${X[@]}                             # all elements
32782 32783 32784 32785 32786 32787 32788 32789 32790 32791 32792 32793 32794
$ Y=($(awk '{print $2}' file))
$ echo ${X[2]}, ${Y[2]}                    # third pair
32784, 01
1 Like

Here is another example, saving $1 in array val

FNR == NR {
  />/ && idx[FNR] = ++i
  $2 || val = $1      # Store source location
  next
}
1 Like

Thanks to all for solving my problem