Learning awk(1)–內建變數

來源:互聯網
上載者:User

Built-in Variablesawk的內建變數:

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。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.