【发布时间】:2011-10-23 06:28:21
【问题描述】:
是否可以这样做:
$ cat foo.txt
1 2 3 4
foo bar baz
hello world
$ awk '{ for(i in $){ print $[i]; } }' foo.txt
1
2
3
4
foo
bar
baz
hello
world
我知道你可以这样做:
$ awk '{ split($0,array," "); for(i in array){ print array[i]; } }' foo.txt
2
3
4
1
bar
baz
foo
world
hello
但是结果不正常。
【问题讨论】:
-
是的,关联数组是无序的集合。