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

查看:689
本文介绍了如何在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天全站免登陆