QTAwk offers the following built-in variables. The variables may be set by the user. Section Built In Variable List contains a list of all built-in variables for reference.
| _arg_chk | TRUE/FALSE. Default value = 0. If assigned a FALSE value, the number of arguments passed to a user defined function is checked only to ensure that the number is not more than defined. Arguments defined, but not passed are initialized and passed for use as local variables as in Awk. If assigned a true value, the number of arguments passed to a user defined function is checked against the number defined for the function, unless the function was defined with a variable number of arguments. If the number passed is not exactly equal to the number defined, an error message is issued and execution halted. For this case, any local variables must be defined with the local keyword. | ||||||||||||||||||||||||
| ARGC | Set equal to the number of arguments passed to QTAwk | ||||||||||||||||||||||||
| ARGI | Equal to the index value in ARGV of the
NEXT command line argument to be processed. This value may be changed
and will change the array element of ARGV processed next.
When the last element of ARGV is the current input file, ARGI
is set to one of two integer values:
Setting ARGI to zero, ARGC or a value for which there is no element of ARGV with a corresponding index value, will cause the current input file to be the last command line argument processed. |
||||||||||||||||||||||||
| ARGV | One-dimensional array with elements equal to the arguments passed to QTAwk. The index values are integers ranging in value from zero to ARGC. ARGV[0] equals the filename by which QTAwk was invoked, including full path information, if used in the invocation. | ||||||||||||||||||||||||
| CLENGTH | Assigned the length of string matched in a case statement using a regular expression for the case label. | ||||||||||||||||||||||||
| CSTART | Assigned the start index of the string matched in a case statement using a regular expression for the case label. | ||||||||||||||||||||||||
| CONVFMT | Format for converting string values to floating point numbers. Default value of "%.6g". Refer to section Numerics and Strings for a discussion on the use of CONVFMT in converting strings to numerics. | ||||||||||||||||||||||||
| CYCLE_COUNT | Value for the current cycle through the outer pattern match loop for the current record. Value incremented by the cycle statement. | ||||||||||||||||||||||||
| DEGREES | TRUE/FALSE. Default value = 0. If assigned a false value, trigonometric functions assume radian values are passed and return radian values. If assigned a TRUE value, trigonometric functions assume degree values are passed and return degree values. | ||||||||||||||||||||||||
| DELAY_INPUT_PARSE | TRUE/FALSE. Default value = 0. Used to delay parsing of the
current input record until the value of NF or one of
the field variables, $i, 1 <= i <= NF, is needed. If
the value is true, then the input record is not parsed until necessary.
For utilities which do not reference NF or the field
variables, $i, in any pattern expressions (or seldom executed pattern
expressions), delaying the parsing of the input record can speed the
execution of the utility significantly. The normal sequence of
execution is:
The fourth step in the above sequence can be delayed until a field variable value or NF is needed by setting DELAY_INPUT_PARSE to a true value. |
||||||||||||||||||||||||
| ECHO_INPUT | TRUE/FALSE. Default value = 0. If assigned a true value, when
reading from the keyboard file,
the input is echoed to the standard output file, normally the console
display.
Any characters read from the standard input file, stdin, are echoed to the standard output file, stdout, if ECHO_INPUT has a true value. If ECHO_INPUT has a false value, then characters read from stdin are not echoed to stdout. When the input to QTAwk has been redirected or piped by the operating system, or the input file has been specified on the command line as a single hyphen, '-', then any input read will be echoed to stdout according to the value of ECHO_INPUT. Since the default value of ECHO_INPUT is 0, the following simple command line utility: QTAwk "{print;}" <input_file will display a single copy of each input line. Modifying the utility as: QTAwk "BEGIN{ECHO_INPUT=1;}{print;}" <input_file will display two copies of each record from the redirected input file. The first record will be displayed because of the echoed input from 'stdin'. The second copy of the input record will be from the explicit print statement. When the standard input file is the keyboard, any characters read are always echoed to the console display. In addition, if ECHO_INPUT is true, then any characters read are also echoed to the standard output file. When the standard input file is redirected from a file or piped from the output of another application program, it is convenient to set ECHO_INPUT to a false value to prevent echoing each input character to the standard output file. For input read from the keyboard file with the fgetc function, ECHO_INPUT should be set to a true value to display key values as they are pressed. The following table shows the effect of ECHO_INPUT on input from the standard input file and the keyboard file:
|
||||||||||||||||||||||||
| ENVIRON | One-dimensional array with elements equal to the environment
strings passed to QTAwk. The index values are integers ranging
in value from zero to the number of environment strings defined less
one.
For example, running the following simple utility will display all environment strings defined and passed to QTAwk: C:\>qtawk "BEGIN{for(i in ENVIRON)print i,ENVIRON[i];}"
The following is typical of the output obtained: 0 COMSPEC=C:\OS2\MDOS\COMMAND.COM |
||||||||||||||||||||||||
| FALSE | Predefined with zero, 0, constant value. | ||||||||||||||||||||||||
| FIELDFILL | This variable value is used only when field splitting is based on FIELDWIDTHS rather than FS. If field splitting is based on FIELDWIDTHS, then the string value of this variable is used to fill a field when the replacement value is less than the field width or if the field changed is greater than the number of fields in the original record. If the field changed is greater than the number of fields defined in FIELDWIDTHS the extra fields created are initialized as null strings separated by the string value of OFS. The default value is a single blank character. | ||||||||||||||||||||||||
| FIELDWIDTHS | When assigned a string value containing space separated
integral
numbers of the form:
n1 n2 n3 ... nn the splitting of input records into fields is governed by the numbers in FIELDWIDTHS rather than FS. Each number in FIELDWIDTHS specifies the width of a field including columns between fields. If you want to ignore the columns between fields, you can specify the width as a separate field that is subsequently ignored. When the value FIELDWIDTHS does not match this form, field splitting is done using FS in the usual manner. If the length of the input record is greater than the sum of the field widths specified in FIELDWIDTHS. QTAwk creates an additional field and assigns the remainder of the input record to the field. Assigning the following string to FIELDWIDTHS: FIELDWIDTHS = "8 25 6 15 9 10"; QTAwk will break subsequent records into 1 to 7 fields depending on the record length. For records with a length of exactly 73 (== 8 + 25 + 6 + 15 + 9 + 10), each field has the lengths specified. For records with greater than 73 characters, the additional characters are assigned to field 7. For records with less than 73 characters, QTAwk creates fields until the characters in the record are exhausted. This variable is especially helpful when used in conjunction with the RECLEN for fixed length input records. For example, a "dir" under PC/MS-DOS produces records of fixed length as follows: 15:31:50.44>dir After reading the first 5 records, setting: RECLEN = 40; Allows for easily accessing each component of the listing as follows: $1 ==> filename stringNote that fields $2, $4, $6, $8, $10, $12 and $14 are separator columns in the directory listing and have been ignored. $17 is the newline, '\n', character separating records. If RECLEN had not been set, i.e. left with a zero value, then $17 would be the null string since the the newline character would not be part of the record. For HPFS under OS/2, the directory listing is no longer a fixed length, since filenames are no longer fixed length. The following is typical of a directory listing for HPFS: The volume label in drive C is OS2. Leaving RECLEN as zero and setting FIELDWIDTHS as: FIELDWIDTHS = "2 1 2 1 2 2 2 1 2 1 1 9 1 10 2"; The components of the directory listing can be accessed via the fields as: $1 ==> file date month Judicious use of the FIELDWIDTHS variable with records with fields with precisely defined sizews, can make accessing particular fields very easy. |
||||||||||||||||||||||||
| FILEATTR | Contains the attributes of the current input file as an integer. The integer defines the attributes in the same manner as the variable for the findfile function defines the attributes for the files found by that function. Changing the value of this variable has no effect on the attributes of the current input file. | ||||||||||||||||||||||||
| FILEDATE | Contains the date of the current input file as a Julian Day Number. Refer to the jdn function for a definition of the Julian Day Number. The _ftime function may be used to format the date. Changing the value of this variable has no effect on the date of the current input file. | ||||||||||||||||||||||||
| FILEDATE_CREATE | Contains the CREATION date of the current input file as a Julian Day Number. Refer to the jdn function for a definition of the Julian Day Number. The _ftime function may be used to format the date. Changing the value of this variable has no effect on the creation date of the current input file. On PC/MS-DOS systems, this value of this variable equals the value of FILEDATE. | ||||||||||||||||||||||||
| FILEDATE_LACCESS | Contains the last file ACCESS date of the current input file as a Julian Day Number. Refer to the jdn function for a definition of the Julian Day Number. The _ftime function may be used to format the date. Changing the value of this variable has no effect on the last access date of the current input file. On PC/MS-DOS systems, this value of this variable equals the value of FILEDATE. | ||||||||||||||||||||||||
| FILENAME | Equal to the string value of current input file, NOT
including any path specified. If assigned a new value, the file with a
name equal to
the new string value is opened (or an error message displayed if the
file
cannot be opened). The new file becomes the current input file. The
former
input file is not closed and input may continue from the current
position
by re-assigning FILENAME, putting the name in ARGV
for future use or read with the fgetline
function.
If assigned a new string value by the user's utility, the full drive and path must be specified if necessary to find the file. QTAwk will strip off the drive and path and assign the filename to the FILENAME variable. The following statements will save the current filepath and name and re-assign it for later use: # Save Current File Name |
||||||||||||||||||||||||
| FILEPATH | Contains the drive and path of the current input file. The path string ends with the subdirectory separator character. Changing the value of this variable has no effect on the path of the current input file. | ||||||||||||||||||||||||
| FILE_SEARCH | TRUE/FALSE values. Default value = 0. Value determines whether next input record read from the current input file is the next physical record or the next record(s) matching a pattern in FILE_SEARCH_PAT. If assigned a false value, then the next physical record is read. If assigned a true value, then the next record(s) matching a pattern in FILE_SEARCH_PAT is read. Multiple records may be read if SPAN_RECORDS is true and the match spans more than one record. See Pattern/Actions for a more complete explanation of searching the input file for the next record. | ||||||||||||||||||||||||
| FILE_SEARCH_PAT | Assigned by the user to the patterns to match in the current input file if FILE_SEARCH. contains a true value. If FILE_SEARCH_PAT is an array, then all array elements are scanned for matches and the MATCH_INDEX built-in variable is set accordingly. See Pattern/Actions for a more complete explanation of searching the input file for the next record. | ||||||||||||||||||||||||
| FILESIZE | Contains the size in bytes of the current input file. Changing the value of this variable has no effect on the size of the current input file. | ||||||||||||||||||||||||
| FILE_SORT | The string value of this variable defines the sort order for
the
array returned by the findfile
function. The default value is the null string, i.e., the array
contains files in the order returned by the operating system.
Valid character values for sorting are given in the table below. Note that case is unimportant.
Any other character(s) will be ignored. If multiple sort options are specified, the files returned are sorted in the order of preference given. For example: # Will Sort By Write Date, Write Time, |
||||||||||||||||||||||||
| FILETIME | Contains the time of the current input file as seconds since midnight. The _ftime function may be used to format the time. Changing the value of this variable has no effect on the time of the current input file. | ||||||||||||||||||||||||
| FILETIME_CREATE | Contains the CREATION time of the current input file as seconds since midnight. The _ftime function may be used to format the time. Changing the value of this variable has no effect on the creation time of the current input file. On PC/MS-DOS systems the value of this variable equals the value of FILETIME. | ||||||||||||||||||||||||
| FILETIME_LACCESS | Contains the last file ACCESS time of the current input file as seconds since midnight. The _ftime function may be used to format the time. Changing the value of this variable has no effect on the lastr access time of the current input file. On PC/MS-DOS systems the value of this variable equals the value of FILETIME. | ||||||||||||||||||||||||
| FNR | Equal to current record number of the current input file. If
the current value of $0 contains more than one input record, then FNR
contains the number of the last record in $0. See the definition of the
built-in variables FILE_SEARCH, FILE_SEARCH_PAT and SPAN_RECORDS and Pattern-Action Pairs for a more
complete explanation of searching the input file for the next record
and how $0 may contain more than one input record.
See also NR. |
||||||||||||||||||||||||
| FS | Value of the current input field separator. If FIELDWIDTHS is not assigned a proper value for
record splitting, then the value of FS is used for splitting
the
current input record into fields. Update: 11-27-2005 - If the value of FS is changed, the current record is immediately re-parsed. This is useful if a field variable has been changed and the new value contains separator characters within the value. For example, given the record: This would be record number:xxxxx with the file and the 5th field is changed to replace the colon, ':', with a single blank: number:xxxxx --> number xxxxx Then the 5th field would be two words which would normally be separated into two fields. To force the re-parsing simply assign FS to itself, thus: FS = FS; The record is immediately re-parsed when the assignment is accomplished and the number of fields is increased from 8 to 9. The default value for FS is /{_z}+/ == /[[:space:]]+/, i.e., any consecutive white space characters. If FS is set on the command line or in the user utility then the following rules apply (see also RS):
If FS is any other single character, such as ",", then each occurrence of that character separates two fields. Two consecutive occurrences delimit an empty field. If the character occurs at the beginning or the end of the line, that too delimits an empty field. The space character is the only single character which does not follow these rules. Suppose you want single spaces to separate fields the way single commas were used above. You can set FS to /[\s]/. This regular expression matches a single space and nothing else. There is an important difference between the two cases:
For both values of FS, fields are separated by runs of spaces and/or tabs. However, in the first case, QTAwk will first strip leading and trailing whitespace from the record before parsing the record into fields. For example, with the following input record: " a b c d e f " if FS is the default, then the first field of the input record is: "a" If, however, FS is set as: FS = /{_z}+/; then the first field of the input record is a null string since the leading and trailing white space have not been stripped from the record. Additionally, if any field is changed the record is rebuilt. The rebuilding process can occur in two ways depending upon the value of the built-in variable, RETAIN_FS. If RETAIN_FS is false, the default value, then QTAwk rebuilds the record by concatenating the fields separated by the string value of OFS. Leading and trailing white space are not retained. If, however, the value of RETAIN_FS is true, then if any field is changed, the new value REPLACES the old value in the input record. All other characters of the input record are unchanged. Thus, the following short utility: {
the output for the above input record is: " a b c d e f " If the following BEGIN action is added to the above utility, BEGIN {
then the output is: " a b c d e f " There are times when you may want to examine each character of
a record separately. In QTAwk, this is easy to do, you simply
assign the null string to FS: In this case, each character in the record will become a separate field. {
With the input record: "a b c d e f" the output is: Field 1: a |
||||||||||||||||||||||||
| Gregorian | TRUE/FALSE. Default == 1. If assigned a true value, QTAwk assumes the Gregorian Calendar in computing the Julian Day Number in the jdn function. The value also affects the calendar used in converting a Julian Day Number to calendar date by the _ftime function. If assigned a false value, QTAwk assumes the Julian Calendar. | ||||||||||||||||||||||||
| IGNORECASE | TRUE/FALSE. Default == 0. If assigned a true value, QTAwk
ignores case in any operation comparing two strings and for single
character comparisons. The affected comparisons include:
|
||||||||||||||||||||||||
| LOCALE | This variable is a single dimensioned vector containing the
string values specific to the current locale. The following indices are
defined
(The string in parenthsis is the value for the 'en' locale): (The
indices
are listed in sorted order)
|
||||||||||||||||||||||||
| LONGEST_EXP | TRUE/FALSE. Default == 1. If assigned a true value, the
longest
string matching a regular expression is found in:
If assigned a false value, then the first string matching the regular expression is found. |
||||||||||||||||||||||||
| MATCH_INDEX | Set to the string value of the index of the matching element when an array is used for matching. QTAwk uses the string value of SUBSEP to separate indices for multidimensional arrays. | ||||||||||||||||||||||||
| MAX_CYCLE | The maximum value for CYCLE_COUNT when cycling through outer pattern match loop with the current input record. Default value == 100. Refer to the discussion of the cycle statement. | ||||||||||||||||||||||||
| MLENGTH | Assigned the length of the string matched by the match operators, ~~ and !~, used in expressions. | ||||||||||||||||||||||||
| MODULES |
This is a singly dimensioned
array. The index for each array element is the name of a currently
loaded module and the element value is the module count when the module
was loaded. When a module is unloaded, the array element corresponding
to that module is deleted from the array. The element index by zero,0, equals the count of currently loaded modules. |
||||||||||||||||||||||||
| Module_Path |
This
variable is set in the configuration file, '.qtawkrc'. The
variable specifies paths to be searched for module files.
Multiple paths may be specified, separated by semi-colons. The paths
specified are searched for module files in the order specified. If a
drive and/or path is specified with an module filename, then that drive
and path only are searched for the desired file. If no drive or path is
specified with an module filename,
then the current directory is searched and then the paths specified in Module_Path.
The search sequence for files follows the the
order:
The value of Module_Path may be reset at any time by the user's utility to change the paths to be searched for module files. Setting the value of Module_Path to a false value, will null the directory search, only the current directory will be searched. |
||||||||||||||||||||||||
| MSTART | Assigned the start index of the string matched by the match operators, ~~ and !~ used in expressions. | ||||||||||||||||||||||||
| NF | Equal to the number of fields in the current input record.
The action of QTAwk when NF is changed reflects the
intuitive effect of changing NF. If the new value is less
than the current value, the current input line is shortened by
truncating at the end of the field corresponding to the new NF
value.
If the new value of NF is greater than the current value, the current input line is lengthened. The method by which QTAwk split the current record into fields determines how the record is lengthened. If QTAwk is using the value of FS to split records into fields, then the current record is lengthened by concatenating empty fields separated by the output field separator string, OFS, onto the end of the record. If field splitting is currently done using the FIELDWIDTHS variable, then, QTAwk follows the following rules for adding new fields:
|
||||||||||||||||||||||||
| NG | Set to the number of the GROUP expression matching the current input record for GROUP patterns. | ||||||||||||||||||||||||
| NR | Total number of records read so far across all input files. See also FNR. | ||||||||||||||||||||||||
| OFMT | Conversion format for outputting floating point numbers. Default value of "%.6g". Whenever a floating point number, either a constant or a variable value, is specified for output with the print function, the value is formatted for output using the string value of OFMT. | ||||||||||||||||||||||||
| OFS | Output field separator. Default value of a single blank, '\s'. Whenever more than one argument is listed for output with the print function, each argument is output separated by the string value of OFS. | ||||||||||||||||||||||||
| ORS | Output record separator. Default value of a single newline character, '\n'. The string value of ORS is concatenated to the output of the print function. | ||||||||||||||||||||||||
| POSIX |
This array contains the strings used in the
replacement of the regular expression character classes: [:alpha:],
[:alnum:], ... , [:xdigit:].
Since these strings are dependent on the execution locale, this change
makes
these strings readily available.The array elements are:
|
||||||||||||||||||||||||
| PROCINFO |
This builtin variable is an
array containing information on the QTAwk
process running. Ths array
has the following array elements and indices indicated:
|
||||||||||||||||||||||||
| RECLEN | If assigned a non-zero numeric value, then the current input
file is assumed to consist of fixed length records with the record
length equal to the integral value of RECLEN. When RECLEN
determines input records, RT is assigned the null
string whenever a record is read from the current input file.
Note: Under OS/2, whenever RECLEN is assigned a non-zero value, the current input file is read as a "binary" file. Normally, the current input file is opened in "text" mode under OS/2, i.e., Carriage Return/Line Feed pairs are translated to single Line Feed characters. However, when fixed length records are being read, then the translation is no longer performed. The translation may also be turned off with the command line option, "-Wi". Refer to Command Line Options |
||||||||||||||||||||||||
| RLENGTH | Assigned the length of the string matched in the match function. | ||||||||||||||||||||||||
| RSTART | Assigned the start index of the string matched in the match function. | ||||||||||||||||||||||||
| RETAIN_FS | TRUE/FALSE. Default value = 0. The value of this variable is used only if input record fields are determined by FS and not by the FIELDWIDTHS variable. If assigned a false value, and FS is used for field splitting, then OFS is used between fields to reconstruct $0 whenever a field value is altered. If assigned a true value, and FS is used for field splitting, the original field separator characters are retained in reconstructing $0 whenever a field value is altered. | ||||||||||||||||||||||||
| RS | Input record separator. The default value for RS is
a
single newline character, '\n'. If RS is set on the command
line
or in the user utility then the following rules apply (see also FS):
The string matching RS is assigned to RT. |
||||||||||||||||||||||||
| RT | Assigned the string value of the record terminator whenever a new record is read from the current input file. If fixed length records are used by setting RECLEN, then RT is assigned the null string. | ||||||||||||||||||||||||
| SPAN_RECORDS | TRUE/FALSE value. Default value = 0. Value determines whether or not matches to FILE_SEARCH_PAT or the search pattern in srchrecord or fsrchrecord are allowed to span records. If assigned a false value, matches must be contained in a single record. See Pattern/Actions. for a more complete explanation of searching the input file for the next record. | ||||||||||||||||||||||||
| SUBSEP | A default value of a comma character, ','. The value of SUBSEP is used to separate the index values in MATCH_INDEX when a multidimensional array is used for matching. | ||||||||||||||||||||||||
| TRACE | Control statement tracing. Default value == 0. Determines whether statements are traced during execution. Refer to section Trace Statements for more detailed information on tracing the execution of QTAwk utilities. | ||||||||||||||||||||||||
| TRANS_FROM | String used by stran function for translating characters. Default value is the value of the POSIX variable array member POSIX["upper"]. | ||||||||||||||||||||||||
| TRANS_TO | String used by stran function for translating characters. Default value is the value of the POSIX variable array member POSIX["lower"]. | ||||||||||||||||||||||||
| TRUE | Predefined with one, 1, constant value. | ||||||||||||||||||||||||
| USER_FUNCTIONS |
This is a singly dimensioned
array. The index value of each element is equal to the name of a user
defined function and the value of the array element is equal to the
file in which the user defined function was defined. This applies for
user defined functions which are defined in dynamically loaded modules
also. For example, if two user defined functions have been defined, one in the file "source_file_1.awk" and the second in the file "library_functions.awk", we would have the following array:
As user defined functions are loaded and unloaded via dynamically loaded modules, the appropriate array elements are added and deleted. The element index by zero,0, equals the count of currently defined user defined functions. |
||||||||||||||||||||||||
| QTAwk_Path | The means for defining this variable has changed starting
with version 1.60. Environment variables are no longer used. This
variable now set in the configuration file, '.qtawkrc'. The
variable specifies paths to be searched for input files.
Multiple paths may be specified, separated by semi-colons. The paths
specified are searched for input files in the order specified. If a
drive and/or path is specified with an input filename, then that drive
and path only are searched for the desired file. If no drive or path is
specified with an input filename,
then the current directory is searched and then the paths specified in
QTAwk_Path.
The search sequence for files follows the the
order:
The value of QTAwk_Path may be reset at any time by the user's utility to change the paths to be searched for input files. Setting the value of QTAwk_Path to a false value, e.g., the null string (""), will null the directory search, only the current directory will be searched. |
||||||||||||||||||||||||
| vargc | Assigned by QTAwk the integer value of the count of variable arguments passed to the current invocation of a user defined function defined with a variable number of arguments. Refer to the section Variable Length Argument Lists for a complete discussion of user defined functions with a variable number of arguments. | ||||||||||||||||||||||||
| vargv | A singly-dimensioned array of assigned the arguments passed to the current invocation of a user defined function with a variable number of arguments. Indexing numeric starts at one, 1. Refer to the section Variable Length Argument Lists for a complete discussion of user defined functions with a variable number of arguments. |