User Tools

Site Tools


awk:awk_variables

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
awk:awk_variables [2020/05/06 18:48] peterawk:awk_variables [2021/01/06 15:55] (current) – [FNR] peter
Line 20: Line 20:
 |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 25: 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 "\034".| |SUBSEP|The character used to separate multiple subscripts in array elements, by default "\034".|
 +|TEXTDOMAIN|The text domain of the AWK program.  For compatibility with GNU **gettext**.  The default value is "messages".|
 +
  
 ---- ----
Line 56: 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.
  
-<code bash>+<code awk>
 awk ' awk '
    print "ARGIND   = ", ARGIND; print "Filename = ", ARGV[ARGIND]     print "ARGIND   = ", ARGIND; print "Filename = ", ARGV[ARGIND] 
Line 117: Line 123:
 Its default value is %.6g. Its default value is %.6g.
  
-<code bash>+<code awk>
 awk 'BEGIN { print "Conversion Format =", CONVFMT }' awk 'BEGIN { print "Conversion Format =", CONVFMT }'
 </code> </code>
Line 153: 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.
  
-<code bash>+<code awk>
 awk 'BEGIN { ret = getline < "junk.txt"; if (ret == -1) print "Error:", ERRNO }' awk 'BEGIN { ret = getline < "junk.txt"; if (ret == -1) print "Error:", ERRNO }'
 </code> </code>
Line 198: Line 204:
  
 It represents the number of the current record in the current file. 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'
 +</code>
 +
 +returns:
 +
 +<code>
 +One Two
 +One Two Three
 +</code>
  
 <WRAP info> <WRAP info>
-**NOTE:  The Value of FNR resets with a new file.+**NOTE:**  The Value of FNR resets with a new file.
 </WRAP> </WRAP>
  
Line 227: Line 244:
 When this variable is set, GAWK becomes case-insensitive. When this variable is set, GAWK becomes case-insensitive.
  
-<code bash>+<code awk>
 awk 'BEGIN{IGNORECASE = 1} /peter/' test.txt awk 'BEGIN{IGNORECASE = 1} /peter/' test.txt
 </code> </code>
Line 236: Line 253:
 10   Peter     Terence    Roux        45 10   Peter     Terence    Roux        45
 </code> </code>
 +
 +<WRAP info>
 +**NOTE:**  If IGNORECASE does not work then try:
 +
 +<code bash>
 +awk 'tolower($0) ~ /peter/' test.txt
 +</code>
 +
 +</WRAP>
  
 ---- ----
Line 247: 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**.
  
-<code bash>+<code awk>
 awk 'BEGIN {LINT = 1; a}' awk 'BEGIN {LINT = 1; a}'
 </code> </code>
Line 258: Line 284:
 </code> </code>
  
 +<WRAP info>
 +**NOTE:**  This only works with GAWK, not AWK.
 +</WRAP>
  
 ---- ----
Line 303: 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.
  
-<code bash>+<code awk>
 awk 'BEGIN {print "OFMT = " OFMT}' awk 'BEGIN {print "OFMT = " OFMT}'
 </code> </code>
Line 319: 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.
  
-<code bash>+<code awk>
 awk 'BEGIN {print "OFS = " OFS}' | cat -vte awk 'BEGIN {print "OFS = " OFS}' | cat -vte
 </code> </code>
Line 335: 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.
  
-<code bash>+<code awk>
 awk 'BEGIN {print "ORS = " ORS}' | cat -vte awk 'BEGIN {print "ORS = " ORS}' | cat -vte
 </code> </code>
Line 352: 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.
  
-<code bash>+<code awk>
 awk 'BEGIN { print PROCINFO["pid"] }' awk 'BEGIN { print PROCINFO["pid"] }'
 </code> </code>
Line 370: 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.
  
-<code bash>+<code awk>
 awk 'BEGIN { if (match("One Two Three", "re")) { print RLENGTH } }' awk 'BEGIN { if (match("One Two Three", "re")) { print RLENGTH } }'
 </code> </code>
Line 387: Line 416:
 It represents (input) record separator and its default value is newline. It represents (input) record separator and its default value is newline.
  
-<code bash>+<code awk>
 awk 'BEGIN {print "RS = " RS}' | cat -vte awk 'BEGIN {print "RS = " RS}' | cat -vte
 </code> </code>
Line 404: 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.
  
-<code bash>+<code awk>
 awk 'BEGIN { if (match("One Two Three", "Thre")) { print RSTART } }' awk 'BEGIN { if (match("One Two Three", "Thre")) { print RSTART } }'
 </code> </code>
Line 420: 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.
  
-<code bash>+<code awk>
 awk 'BEGIN { print "SUBSEP = " SUBSEP }' | cat -vte awk 'BEGIN { print "SUBSEP = " SUBSEP }' | cat -vte
 </code> </code>
Line 436: Line 465:
 It represents the entire input record. It represents the entire input record.
  
-<code bash>+<code awk>
 awk '{print $0}' test.txt awk '{print $0}' test.txt
 </code> </code>
Line 459: Line 488:
 It is used to find the localized translations for the program's strings. It is used to find the localized translations for the program's strings.
  
-<code bash>+<code awk>
 awk 'BEGIN { print TEXTDOMAIN }' awk 'BEGIN { print TEXTDOMAIN }'
 </code> </code>
Line 480: 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.
  
-<code bash>+<code awk>
 awk '{print $2 "\t" $5}' test.txt awk '{print $2 "\t" $5}' test.txt
 </code> </code>
awk/awk_variables.1588790884.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki