AWK-BEGIN and END Special Patterns【每日一译】--2013-1-31

BEGIN and END are special patterns. They are not used to match input records. Rather, they are
used for supplying start-up or clean-up information to your awk script. A BEGIN rule is executed,
once, before the fi rst input record has been read. An END rule is executed, once, after all the input

has been read. For example:

BEGIN和END是特殊的模式。它们不用匹配输入的记录。而是应用于在AWK脚本的开始和结束清理信息方面。

BEGIN规则只被执行一次在第一条记录被读取前。和END规则在所有的输入被读取后执行一次。比如。

awk 'BEGIN { print "Analysis of `foo'" }
/foo/ { ++foobar }

END { print "`foo' appears " foobar " times." }' BBS-list


This program finds the number of records in the input le `BBS-list' that contain the string
`foo'. The BEGIN rule prints a title for the report. There is no need to use the BEGIN rule

to initialize the counter foobar to zero, as awk does this for us automatically

这个程序找出包含字符“foo“的记录数在“BBS-list"文件中。BEGIN规则在报告前打印标题。

它不需要使用BEGIN规则去初始化计数器foobar到0,AWK会为我们自动去完成这个动作;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值