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:53] peterawk:awk_variables [2021/01/06 15:55] (current) – [FNR] peter
Line 32: Line 32:
 |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 60: 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 121: 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 157: 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 202: 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>
Line 231: 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 240: 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 251: 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 262: Line 284:
 </code> </code>
  
 +<WRAP info>
 +**NOTE:**  This only works with GAWK, not AWK.
 +</WRAP>
  
 ---- ----
Line 307: 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 323: 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 339: 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 356: 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 374: 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 391: 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 408: 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 424: 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 440: 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 463: 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 484: 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.1588791232.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki