awk零碎1【每日一译】--2013-02-01

本文介绍AWK中变量的使用方式,包括默认初始化为空值的特点及如何根据位置进行赋值。此外还讲解了如何通过ARGV数组获取命令行参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Variables in awk can be assigned either numeric or string values. By default, variables are

initialized to the null string, which is eff ectively zero if converted to a number. There is no need
to \initialize" each variable explicitly in awk, the way you would in C or most other traditional
languages.


译:在AWK中变量可被赋予或者是数字或者是字符串的值。默认是被赋予为空值,如果空串被转

为数为数字它将为0.不需要明确去初始化在AWK中的变量值,而在C或者大多数其它传统语方它是

需要的。


Otherwise, the variable assignment is performed at a time determined by its position among the
input file arguments: after the processing of the preceding input fi le argument. For example:
awk '{ print $n }' n=4 inventory-shipped n=2 BBS-list

译:同样的,变量的赋值执行取决于在输入文件参数中它所属的位置:在之前输入文件处理参数

的后面。比如

awk '{ print $n }' n=4 inventory-shipped n=2 BBS-list

------------------------------------------------------------------------------------------------------------------------------------

Command line arguments are made available for explicit examination by the awk program in an
array named ARGV

译:ARGC是等待输入参数的个数,ARGV是参数存储的数组;

命令行参数经过AWK的实际测试的可用的,它存储于一个数组名字叫作ARGV;

[oracle@localhost ~]$ awk ' BEGIN{
for (i=0;i<ARGC;i++)
print ARGV[i]}' tmpdata2 tmpdata1

--output---
awk
tmpdata2
tmpdata1


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值