In programs that use arrays, often you need a loop that executes once for each element of an
array. In other languages, where arrays are contiguous and indices are limited to positive integers,
this is easy: the largest index is one less than the length of the array, and you can FI nd all the valid
indices by counting from zero up to that value. This technique won’t do the job in awk, since any
number or string may be an array index. So awk has a special kind of for statement for scanning
an array:
在使用数组的程序中,对于数组中的每个元素通常需要循环一次执行一次。在其它语言中,数组是连
续以及它的索引条目是正整数,很简单的:最大的索引条目比数组的长度小1,并且你可以所有的可用
条目通过从0计算起到刚的那个值(索引最大条目减1)。这个技术在AWK中是不做此工作的,因为任何
的数字或者字符串都可以作为索引的条目。所以AWK拥有一个指定的遍历数且的语句如下:
for (var in array)
body
This loop executes body once for each di ferent value that your program has previously used as an
index in array, with the variable var set to that index.
这个循环执行体对于不同的值每次执行一次,这些值是前面程序中在数组中作为索引条目来使用的,
使用变量VAR来设置索引的条目。
Here is a program that uses this form of the for statement. The FIrst rule scans the input records
and notes which words appear (at least once) in the input, by storing a 1 into the array used with
the word as index. The second rule scans the elements of used to nd all the distinct words that
appear in the input. It prints each word that is more than 10 characters long, and also prints the
number of such words. See Chapter 11 [Built-in Functions], page 89, for more information on the
built-in function length.
这个程序语句使用这种格式。它第一个规则扫描输入记录并且记录了哪些输入的单词至少出现过一次,
通过存储1在数组中,使用单词来作为索引条目。它输出每个单词,它的长度是大于10的单词,并且
打印此类单词的数量。
例子:
# Record a 1 for each word that is used at least once.
{
for (i = 1; i 10) {
++num_long_words
print x 输出索引条目,其实也就是我们要的内容
}
print num_long_words, "words longer than 10 characters"
}
[oracle@localhost ~]$ awk -f awkf zbk_data
eeeeeeeeeee
zhangwiangjash
ccccedfasd
aaaaaaaaaa
dddddddddd
bbbbbbbbbbb
6 words longer than 10 characters
[oracle@localhost ~]$ cat zbk_data
aaaaaaaaaa bbbbbbbbbbb ccccccccc
dddddddddd eeeeeeeeeee ghghghghg
ccccedfasd zhangwiangjash goafsced
aaaaaaaaaa bbbbbbbbbbb ccccccccc
aaaaaaaaaa bbbbbbbbbbb ccccccccc
aaaaaaaaaa bbbbbbbbbbb ccccccccc
aaaaaaaaaa bbbbbbbbbbb ccccccccc
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
收到网友提问,PBN程序和ILS程序在衔接时,中间进近航段的保护区该怎么去绘制。 这个问题怎么看呢?首先起始进近航段与中间进近航段存在两种连接方式,一种是直线进近、另一种是转弯进近,两者的保护区是显著不同的。(转弯进近这个说法有点不规范) DOC8168规…