awk:awk_variables
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
awk:awk_variables [2020/05/06 18:42] – peter | awk:awk_variables [2021/01/06 15:55] (current) – [FNR] peter | ||
---|---|---|---|
Line 13: | Line 13: | ||
|BINMODE|Specifies use of “binary” mode for all file I/O.| | |BINMODE|Specifies use of “binary” mode for all file I/O.| | ||
|CONVFMT|The conversion format for numbers, " | |CONVFMT|The conversion format for numbers, " | ||
+ | |ENVIRON|Environment Variables.| | ||
|FIELDWIDTHS|A white-space separated list of field widths. When set the input is parsed into fields of fixed width, instead of using the value of the FS variable as the field separator.| | |FIELDWIDTHS|A white-space separated list of field widths. When set the input is parsed into fields of fixed width, instead of using the value of the FS variable as the field separator.| | ||
+ | |FILENAME|Current filename.| | ||
|FNR|The input record number in the current input file.| | |FNR|The input record number in the current input file.| | ||
|FPAT|A regular expression describing the contents of the fields in a record. When set the input is parsed into fields, where the fields match the regular expression, instead of using the value of the FS variable as the field separator.| | |FPAT|A regular expression describing the contents of the fields in a record. When set the input is parsed into fields, where the fields match the regular expression, instead of using the value of the FS variable as the field separator.| | ||
|FS|The input field separator, a space by default.| | |FS|The input field separator, a space by default.| | ||
|IGNORECASE|Controls the case-sensitivity of all regular expression and string operations.| | |IGNORECASE|Controls the case-sensitivity of all regular expression and string operations.| | ||
+ | |LINT|Provides dynamic control of the –lint option.| | ||
|NF|The number of fields in the current input record.| | |NF|The number of fields in the current input record.| | ||
|NR|The total number of input records seen so far.| | |NR|The total number of input records seen so far.| | ||
Line 23: | Line 26: | ||
|OFS|The output field separator, a space by default.| | |OFS|The output field separator, a space by default.| | ||
|ORS|The output record separator, by default a newline.| | |ORS|The output record separator, by default a newline.| | ||
+ | |PROCINFO|Information about the process.| | ||
+ | |RLENGTH|The length of the string matched by the match function.| | ||
+ | |RSTART|The first position in the string matched by match function.| | ||
|RS|The input record separator, by default a newline.| | |RS|The input record separator, by default a newline.| | ||
|RT|The record terminator.| | |RT|The record terminator.| | ||
|SUBSEP|The character used to separate multiple subscripts in array elements, by default " | |SUBSEP|The character used to separate multiple subscripts in array elements, by default " | ||
+ | |TEXTDOMAIN|The text domain of the AWK program. | ||
+ | |||
---- | ---- | ||
Line 54: | Line 62: | ||
It represents the index in ARGV of the current file being processed. | It represents the index in ARGV of the current file being processed. | ||
- | < | + | < |
awk ' | awk ' | ||
print " | print " | ||
Line 115: | Line 123: | ||
Its default value is %.6g. | Its default value is %.6g. | ||
- | < | + | < |
awk 'BEGIN { print " | awk 'BEGIN { print " | ||
</ | </ | ||
Line 151: | Line 159: | ||
A string indicates an error when a redirection fails for getline or if a close call fails. | A string indicates an error when a redirection fails for getline or if a close call fails. | ||
- | < | + | < |
awk 'BEGIN { ret = getline < " | awk 'BEGIN { ret = getline < " | ||
</ | </ | ||
Line 185: | Line 193: | ||
<WRAP info> | <WRAP info> | ||
**NOTE:** Please note that FILENAME is undefined in the BEGIN block. | **NOTE:** Please note that FILENAME is undefined in the BEGIN block. | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== FNR ===== | ||
+ | |||
+ | It is similar to NR, but relative to the current file. | ||
+ | |||
+ | It is useful when AWK is operating on multiple files. | ||
+ | |||
+ | It represents the number of the current record in the current file. | ||
+ | |||
+ | <code bash> | ||
+ | echo -e "One Two\nOne Two Three\nOne Two Three Four" | awk 'FNR < 3' | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | < | ||
+ | One Two | ||
+ | One Two Three | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
</ | </ | ||
Line 211: | Line 244: | ||
When this variable is set, GAWK becomes case-insensitive. | When this variable is set, GAWK becomes case-insensitive. | ||
- | < | + | < |
awk ' | awk ' | ||
</ | </ | ||
Line 220: | Line 253: | ||
10 | 10 | ||
</ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | <code bash> | ||
+ | awk ' | ||
+ | </ | ||
+ | |||
+ | </ | ||
---- | ---- | ||
Line 231: | Line 273: | ||
When assigned the string value fatal, lint warnings become fatal errors, exactly like **--lint=fatal**. | When assigned the string value fatal, lint warnings become fatal errors, exactly like **--lint=fatal**. | ||
- | < | + | < |
awk 'BEGIN {LINT = 1; a}' | awk 'BEGIN {LINT = 1; a}' | ||
</ | </ | ||
Line 242: | Line 284: | ||
</ | </ | ||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | </ | ||
---- | ---- | ||
Line 280: | Line 325: | ||
One Two Three | One Two Three | ||
</ | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== FNR ===== | ||
- | |||
- | It is similar to NR, but relative to the current file. | ||
- | |||
- | It is useful when AWK is operating on multiple files. | ||
- | |||
- | Value of FNR resets with a new file. | ||
---- | ---- | ||
Line 297: | Line 332: | ||
It represents the output format number and its default value is %.6g. | It represents the output format number and its default value is %.6g. | ||
- | < | + | < |
awk 'BEGIN {print "OFMT = " OFMT}' | awk 'BEGIN {print "OFMT = " OFMT}' | ||
</ | </ | ||
Line 313: | Line 348: | ||
It represents the output field separator and its default value is space. | It represents the output field separator and its default value is space. | ||
- | < | + | < |
awk 'BEGIN {print "OFS = " OFS}' | cat -vte | awk 'BEGIN {print "OFS = " OFS}' | cat -vte | ||
</ | </ | ||
Line 329: | Line 364: | ||
It represents the output record separator and its default value is newline. | It represents the output record separator and its default value is newline. | ||
- | < | + | < |
awk 'BEGIN {print "ORS = " ORS}' | cat -vte | awk 'BEGIN {print "ORS = " ORS}' | cat -vte | ||
</ | </ | ||
Line 346: | Line 381: | ||
This is an associative array containing information about the process, such as real and effective UID numbers, process ID number, and so on. | This is an associative array containing information about the process, such as real and effective UID numbers, process ID number, and so on. | ||
- | < | + | < |
awk 'BEGIN { print PROCINFO[" | awk 'BEGIN { print PROCINFO[" | ||
</ | </ | ||
Line 364: | Line 399: | ||
AWK's match function searches for a given string in the input-string. | AWK's match function searches for a given string in the input-string. | ||
- | < | + | < |
awk 'BEGIN { if (match(" | awk 'BEGIN { if (match(" | ||
</ | </ | ||
Line 381: | Line 416: | ||
It represents (input) record separator and its default value is newline. | It represents (input) record separator and its default value is newline. | ||
- | < | + | < |
awk 'BEGIN {print "RS = " RS}' | cat -vte | awk 'BEGIN {print "RS = " RS}' | cat -vte | ||
</ | </ | ||
Line 398: | Line 433: | ||
It represents the first position in the string matched by match function. | It represents the first position in the string matched by match function. | ||
- | < | + | < |
awk 'BEGIN { if (match(" | awk 'BEGIN { if (match(" | ||
</ | </ | ||
Line 414: | Line 449: | ||
It represents the separator character for array subscripts and its default value is \034. | It represents the separator character for array subscripts and its default value is \034. | ||
- | < | + | < |
awk 'BEGIN { print " | awk 'BEGIN { print " | ||
</ | </ | ||
Line 430: | Line 465: | ||
It represents the entire input record. | It represents the entire input record. | ||
- | < | + | < |
awk ' | awk ' | ||
</ | </ | ||
Line 453: | Line 488: | ||
It is used to find the localized translations for the program' | It is used to find the localized translations for the program' | ||
- | < | + | < |
awk 'BEGIN { print TEXTDOMAIN }' | awk 'BEGIN { print TEXTDOMAIN }' | ||
</ | </ | ||
Line 474: | Line 509: | ||
It represents the nth field in the current record where the fields are separated by FS. | It represents the nth field in the current record where the fields are separated by FS. | ||
- | < | + | < |
awk ' | awk ' | ||
</ | </ |
awk/awk_variables.1588790569.txt.gz · Last modified: 2020/07/15 09:30 (external edit)