如何在awk中初始化数组数组? [英] How to initialize an array of arrays in awk?

查看:29
本文介绍了如何在awk中初始化数组数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 AWK 中初始化这样的数组?

Is it possible to initialize an array like this in AWK ?

Colors[1] = ("Red", "Green", "Blue")
Colors[2] = ("Yellow", "Cyan", "Purple")

然后有一个二维数组,其中 Colors[2,3]="Purple".

And then to have a two dimensional array where Colors[2,3]="Purple".

另一个线程我明白这是不可能的(遗憾的是,有没有办法在不滥用 split()" 的情况下一次设置一个数组.无论如何,我想 100% 确定,而且我确信还有其他人有同样的问题.

From another thread I understand that it's not possible ( "sadly, there is no way to set an array all at once without abusing split()" ). Anyways I want to be 100% sure and I'm sure that there are others with the same question.

我正在寻找像上面那样初始化数组的最简单方法,写得好会很好.

I am looking for the easiest method to initialize arrays like the one above, will be nice to have it well written.

推荐答案

感谢您的回答.无论如何,对于那些想要初始化一维数组的人,这里有一个例子:

Thanks for the answers. Anyways, for those who want to initialize unidimensional arrays, here is an example:

SColors = "Red_Green_Blue"
split(SColors, Colors, "_")
print Colors[1] " - " Colors[2] " - " Colors[3]

这篇关于如何在awk中初始化数组数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆