3

Is it possible to initializate an array in AWK with the common list syntax?

array = [val1, val2, val3]

Or is it obligatory to use the index-value syntax?

array[0] = val1
array[1] = val2
array[2] = val3
1

1 Answer 1

7

No and no. This is how you do it:

$ awk 'BEGIN{split("val1 val2 val3",array); for (i in array) print i, array[i]}'
1 val1
2 val2
3 val3

Read the book Effective Awk Programing, 4th Edition, by Arnold Robbins as if you don't know this then there's a lot of other awk basics you're missing too.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.