Learning awk(1)--内建变量

Built-in Variables
awk的内建变量:
ARGC       
同C
ARGIND
   being processed 的index(英文的描述更精确一点)
ARGV  
     同C.
BINMODE
    On non-POSIX systems, specifies use of  binary  mode for all file I/O.  Numeric values of 1, 2,  or  3,specify that input files, output files, or all files, respectively, should use binary I/O.  String val-ues of "r", or "w" specify that input files, or output files,  respectively,  should  use  binary  I/O .String  values of "rw" or "wr" specify that all files should use binary I/O.  Any other string value is treated as "rw", but generates a warning message.
设定文件(输入出/读入出)是否为二进制
CONVFMT   
 The conversion format for numbers, "%.6g", by default.
用来改变数字格式的利器!

ENVIRON

An array containing the values of the current environment.  The array is  indexed  by  the  environment variables, each element being the value of that variable (e.g., ENVIRON["HOME"] might be /home/arnold). Changing this arraydoes not affect the environment seen by programs which gawk spawns via  redirection  or the system() function.

环境变量的设定,从介绍中可以看出其实是一个hash表,支持通过key来查找value,不会改变系统当前的环境变量,gawk使用的是重定向或者使用system函数的方法实现。
      

ERRNO     

If a system error occurs either doing a redirection for getline, during a read for getline, or during aclose(), then ERRNO will contain a string describing the error.  The value is subject to translation in  non-English locales.

返回字串类型的错误码

FIELDWIDTHS

A  white-space  separated  list  of  fieldwidths.  When set, gawk parses the input into fields of fixed width, instead of using the value of the FS variable as the field separator.

设定列宽,这个在严格设定大小的文件中有用,对于列宽未知的情况,还是使用FS设定(但是可以肯定的是设定列宽的操作会更快,想一想问什么:-))

FILENAME   

The name of the current input file.  If no files are specified on the command line, the value of  FILE-NAME is <A1><B0>-<A1><B1>.  However, FILENAME is undefined inside the BEGIN block (unless set by getline).

当前输入文件的名字,在BEGIN块中是未定义的(除非使用getline函数指定)。

FNR        

The input record number in the current input file.

输入文件中的记录条数(因为记录不一定从文件的起始位置开始,而记录之间不一定用换行区分,因此造就了这么困难的表达……)

多理解理解。

IGNORECASE 

Controls  the  case-sensitivity  of  all regular expression and string operations.  If IGNORECASE has a non-zero value, then string comparisons and pattern matching in rules, field splitting with FS,  record separating  with  RS,  regular  expression  matching  with ~ and !~, and the gensub(), gsub(), index(), match(), split(), and sub() built-in functions all ignore case when  doing  regular  expression  opera tions.   NOTE:  Array  subscripting  is  not affected.  However, the asort() and asorti() functions are  affected.  Thus, if IGNORECASE is not equal to zero, /aB/ matches all of the strings "ab", "aB", "Ab",  and  "AB".  As  with  all  AWK  variables,  the  initial value of IGNORECASE is zero, so all regular expression and  string operations are normally case-sensitive.  Under Unix, the full ISO 8859-1 Latin-1  character  set  is used when ignoring case.

设定大小写敏感,针对正则和字符串操作。

LINT       

Provides  dynamic control of the --lint option from within an AWK program.  When true, gawk prints lint  warnings. When false, it does not.  When assigned the string value "fatal", lint warnings become  fatal errors, exactly like --lint=fatal.  Any other true value just prints warnings.

可以用来设置警告为错误--lint=fatal。

NF         

The number of fields in the current input record.

当前数据行列的个数。

NR         

The total number of input records seen so far.

目前输入的记录个数。

OFMT       

The output format for numbers, "%.6g", by default.

设定输出数字的格式。

OFS        

The output field separator, a space by default.

设定输出的列之间的分隔符,默认为空格

ORS        

The output record separator, by default a newline.

设定记录之间的分隔符,默认为换行

PROCINFO   

The  elements  of this array provide access to information about the running AWK program.  On some sys  tems, there may be elements in the array, "group1" through "groupn" for some n, which is the number  of supplementary  groups  that the process has.  Use the in operator to test for these elements.  The following elements are guaranteed to be available:

                   PROCINFO["egid"]   the value of the getegid(2) system call.
                   PROCINFO["euid"]   the value of the geteuid(2) system call.
                   PROCINFO["FS"]     "FS" if field splitting with FS is in effect, or "FIELDWIDTHS"  if  field  splitting with FIELDWIDTHS is in effect.
                   PROCINFO["gid"]    the value of the getgid(2) system call.
                   PROCINFO["pgrpid"] the process group ID of the current process.
                   PROCINFO["pid"]    the process ID of the current process.
                   PROCINFO["ppid"]   the parent process ID of the current process.
                   PROCINFO["uid"]    the value of the getuid(2) system call.
RS         

The input record separator, by default a newline.

设定输入记录之间的分隔符,默认为换行

RT         

The record terminator.  Gawk sets RT to the input text that matched the character or regular expression specified by RS.

设定为和RS一致的**,不管是正则还是字符。

RSTART     

The index of the first character matched by match(); 0 if  no  match.   (This  implies  that  character indices start at one.)

match函数找到的符合条件的第一个索引值,没有找到的话为0

RLENGTH    

The length of the string matched by match(); -1 if no match.

相同字符的长度。

SUBSEP     

The character used to separate multiple subscripts in array elements, by default "\034".

TEXTDOMAIN 

The  text domain of the AWK program; used to find the localized translations for the program‘s strings.

不太理解,需要实例学习,mark。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值