neulab/tldr huggingface dataset:
In the function definition, <newline> characters shall be optional before the opening brace and after the closing brace. Function definitions can appear anywhere in the program where a pattern-action pair is allowed.
Grammar The grammar in this section and the lexical conventions in the following section shall together describe the syntax for awk programs. The general conventions for this style of grammar are described in Section 1.3, Grammar Conventions.  A valid program can be represented as the non- terminal symbol program in the grammar. This formal syntax shall take precedence over the preceding text syntax description.
%token NAME NUMBER STRING ERE %token FUNC_NAME   /* Name followed by '(' without white space. */
/* Keywords */ %token       Begin   End /*          'BEGIN' 'END'                            */
%token       Break   Continue   Delete   Do   Else /*          'break' 'continue' 'delete' 'do' 'else'  */
%token       Exit   For   Function   If   In /*          'exit' 'for' 'function' 'if' 'in'        */
%token       Next   Print   Printf   Return   While /*          'next' 'print' 'printf' 'return' 'while' */
/* Reserved function names */ %token BUILTIN_FUNC_NAME /* One token for the following: * atan2 cos sin exp log sqrt int rand srand * gsub index length match split sprintf sub * substr tolower toupper close system */ %token GETLINE /* Syntactically different from other built-ins. */
/* Two-character tokens. */ %token ADD_ASSIGN SUB_ASSIGN MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN POW_ASSIGN /*     '+='       '-='       '*='       '/='       '%='       '^=' */
%token OR   AND  NO_MATCH   EQ   LE   GE   NE   INCR  DECR  APPEND /*     '||' '&&' '!~' '==' '<=' '>=' '!=' '++'  '--'  '>>'   */
/* One-character tokens. */ %token '{' '}' '(' ')' '[' ']' ',' ';' NEWLINE %token '+' '-' '*' '%' '^' '!' '>' '<' '|' '?' ':' '~' '$' '='
%start program %%
program          : item_list | item_list item ;
item_list        : /* empty */ | item_list item terminator ;
item             : action | pattern action | normal_pattern | Function NAME      '(' param_list_opt ')' newline_opt action | Function FUNC_NAME '(' param_list_opt ')' newline_opt action ;
param_list_opt   : /* empty */ | param_list ;
param_list       : NAME | param_list ',' NAME ;
pattern          : normal_pattern | special_pattern ;
normal_pattern   : expr | expr ',' newline_opt expr ;
special_pattern  : Begin | End ;
action           : '{' newline_opt                             '}' | '{' newline_opt terminated_statement_list   '}' | '{' newline_opt unterminated_statement_list '}' ;
terminator       : terminator NEWLINE |            ';' |            NEWLINE ;
terminated_statement_list : terminated_statement | terminated_statement_list terminated_statement ;
unterminated_statement_list : unterminated_statement | terminated_statement_list unterminated_statement ;
terminated_statement : action newline_opt | If '(' expr ')' newline_opt terminated_statement | If '(' expr ')' newline_opt terminated_statement Else newline_opt terminated_statement | While '(' expr ')' newline_opt terminated_statement | For '(' simple_statement_opt ';' expr_opt ';' simple_statement_opt ')' newline_opt terminated_statement | For '(' NAME In NAME ')' newline_opt terminated_statement | ';' newline_opt | terminatable_statement NEWLINE newline_opt | terminatable_statement ';'     newline_opt ;
unterminated_statement : terminatable_statement | If '(' expr ')' newline_opt unterminated_statement | If '(' expr ')' newline_opt terminated_statement Else newline_opt unterminated_statement | While '(' expr ')' newline_opt unterminated_statement | For '(' simple_statement_opt ';' expr_opt ';' simple_statement_opt ')' newline_opt unterminated_statement | For '(' NAME In NAME ')' newline_opt unterminated_statement ;
terminatable_statement : simple_statement | Break | Continue | Next | Exit expr_opt | Return expr_opt | Do newline_opt terminated_statement While '(' expr ')' ;
simple_statement_opt : /* empty */ | simple_statement ;
simple_statement : Delete NAME '[' expr_list ']' | expr | print_statement ;
print_statement  : simple_print_statement | simple_print_statement output_redirection ;
simple_print_statement : Print  print_expr_list_opt | Print  '(' multiple_expr_list ')' | Printf print_expr_list | Printf '(' multiple_expr_list ')' ;
output_redirection : '>'    expr | APPEND expr | '|'    expr ;
expr_list_opt    : /* empty */ | expr_list ;
expr_list        : expr | multiple_expr_list ;
multiple_expr_list : expr ',' newline_opt expr | multiple_expr_list ',' newline_opt expr ;
expr_opt         : /* empty */ | expr ;
expr             : unary_expr | non_unary_expr ;
unary_expr       : '+' expr | '-' expr | unary_expr '^'      expr | unary_expr '*'      expr | unary_expr '/'      expr | unary_expr '%'      expr | unary_expr '+'      expr | unary_expr '-'      expr | unary_expr          non_unary_expr | unary_expr '<'      expr | unary_expr LE       expr | unary_expr NE       expr | unary_expr EQ       expr | unary_expr '>'      expr | unary_expr GE       expr | unary_expr '~'      expr | unary_expr NO_MATCH expr | unary_expr In NAME | unary_expr AND newline_opt expr | unary_expr OR  newline_opt expr | unary_expr '?' expr ':' expr | unary_input_function ;
non_unary_expr   : '(' expr ')' | '!' expr | non_unary_expr '^'      expr | non_unary_expr '*'      expr | non_unary_expr '/'      expr | non_unary_expr '%'      expr | non_unary_expr '+'      expr | non_unary_expr '-'      expr | non_unary_expr          non_unary_expr | non_unary_expr '<'      expr | non_unary_expr LE       expr | non_unary_expr NE       expr | non_unary_expr EQ       expr | non_unary_expr '>'      expr | non_unary_expr GE       expr | non_unary_expr '~'      expr | non_unary_expr NO_MATCH expr | non_unary_expr In NAME | '(' multiple_expr_list ')' In NAME | non_unary_expr AND newline_opt expr | non_unary_expr OR  newline_opt expr | non_unary_expr '?' expr ':' expr | NUMBER | STRING | lvalue | ERE | lvalue INCR | lvalue DECR | INCR lvalue | DECR lvalue | lvalue POW_ASSIGN expr | lvalue MOD_ASSIGN expr | lvalue MUL_ASSIGN expr | lvalue DIV_ASSIGN expr | lvalue ADD_ASSIGN expr | lvalue SUB_ASSIGN expr | lvalue '=' expr | FUNC_NAME '(' expr_list_opt ')' /* no white space allowed before '(' */ | BUILTIN_FUNC_NAME '(' expr_list_opt ')' | BUILTIN_FUNC_NAME | non_unary_input_function ;
print_expr_list_opt : /* empty */ | print_expr_list ;
print_expr_list  : print_expr | print_expr_list ',' newline_opt print_expr ;
print_expr       : unary_print_expr | non_unary_print_expr ;
unary_print_expr : '+' print_expr | '-' print_expr | unary_print_expr '^'      print_expr | unary_print_expr '*'      print_expr | unary_print_expr '/'      print_expr | unary_print_expr '%'      print_expr | unary_print_expr '+'      print_expr | unary_print_expr '-'      print_expr | unary_print_expr          non_unary_print_expr | unary_print_expr '~'      print_expr | unary_print_expr NO_MATCH print_expr | unary_print_expr In NAME | unary_print_expr AND newline_opt print_expr | unary_print_expr OR  newline_opt print_expr | unary_print_expr '?' print_expr ':' print_expr ;
non_unary_print_expr : '(' expr ')' | '!' print_expr | non_unary_print_expr '^'      print_expr | non_unary_print_expr '*'      print_expr | non_unary_print_expr '/'      print_expr | non_unary_print_expr '%'      print_expr | non_unary_print_expr '+'      print_expr | non_unary_print_expr '-'      print_expr | non_unary_print_expr          non_unary_print_expr | non_unary_print_expr '~'      print_expr | non_unary_print_expr NO_MATCH print_expr | non_unary_print_expr In NAME | '(' multiple_expr_list ')' In NAME | non_unary_print_expr AND newline_opt print_expr | non_unary_print_expr OR  newline_opt print_expr | non_unary_print_expr '?' print_expr ':' print_expr | NUMBER | STRING | lvalue | ERE | lvalue INCR | lvalue DECR | INCR lvalue | DECR lvalue | lvalue POW_ASSIGN print_expr | lvalue MOD_ASSIGN print_expr | lvalue MUL_ASSIGN print_expr | lvalue DIV_ASSIGN print_expr | lvalue ADD_ASSIGN print_expr | lvalue SUB_ASSIGN print_expr | lvalue '=' print_expr | FUNC_NAME '(' expr_list_opt ')' /* no white space allowed before '(' */ | BUILTIN_FUNC_NAME '(' expr_list_opt ')' | BUILTIN_FUNC_NAME ;
lvalue           : NAME | NAME '[' expr_list ']' | '$' expr ;
non_unary_input_function : simple_get | simple_get '<' expr | non_unary_expr '|' simple_get ;
unary_input_function : unary_expr '|' simple_get ;
simple_get       : GETLINE | GETLINE lvalue ;
newline_opt      : /* empty */ | newline_opt NEWLINE ;
This grammar has several ambiguities that shall be resolved as follows:
*  Operator precedence and associativity shall be as described in Table 4-1, Expressions in Decreasing Precedence in awk.
*  In case of ambiguity, an else shall be associated with the most immediately preceding if that would satisfy the grammar.
*  In some contexts, a <slash> ('/') that is used to surround an ERE could also be the division operator.  This shall be resolved in such a way that wherever the division operator could appear, a <slash> is assumed to be the division operator. (There is no unary division operator.)
Each expression in an awk program shall conform to the precedence and associativity rules, even when this is not needed to resolve an ambiguity. For example, because '$' has higher precedence than '++', the string "$x++--" is not a valid awk expression, even though it is unambiguously parsed by the grammar as "$(x++)--".
One convention that might not be obvious from the formal grammar is where <newline> characters are acceptable. There are several obvious placements such as terminating a statement, and a <backslash> can be used to escape <newline> characters between any lexical tokens. In addition, <newline> characters without <backslash> characters can follow a comma, an open brace, logical AND operator ("&&"), logical OR operator ("||"), the do keyword, the else keyword, and the closing parenthesis of an if, for, or while statement. For example:
{ print  $1, $2 }
Lexical Conventions The lexical conventions for awk programs, with respect to the preceding grammar, shall be as follows:
1. Except as noted, awk shall recognize the longest possible token or delimiter beginning at a given point.
2. A comment shall consist of any characters beginning with the <number- sign> character and terminated by, but excluding the next occurrence of, a <newline>.  Comments shall have no effect, except to delimit lexical tokens.
3. The <newline> shall be recognized as the token NEWLINE.
4. A <backslash> character immediately followed by a <newline> shall have no effect.
5. The token STRING shall represent a string constant. A string constant shall begin with the character '"'.  Within a string constant, a <backslash> character shall be considered to begin an escape sequence as specified in the table in the Base Definitions volume of POSIX.1‐2017, Chapter 5, File Format Notation ('\\', '\a', '\b', '\f', '\n', '\r', '\t', '\v').  In addition, the escape sequences in Table 4-2, Escape Sequences in awk shall be recognized. A <newline> shall not occur within a string constant. A string constant shall be terminated by the first unescaped occurrence of the character '"' after the one that begins the string constant. The value of the string shall be the sequence of all unescaped characters and values of escape sequences between, but not including, the two delimiting '"' characters.
6. The token ERE represents an extended regular expression constant. An ERE constant shall begin with the <slash> character. Within an ERE constant, a <backslash> character shall be considered to begin an escape sequence as specified in the table in the Base Definitions volume of POSIX.1‐2017, Chapter 5, File Format Notation.  In addition, the escape sequences in Table 4-2, Escape Sequences in awk shall be recognized. The application shall ensure that a <newline> does not occur within an ERE constant. An ERE constant shall be terminated by the first unescaped occurrence of the <slash> character after the one that begins the ERE constant. The extended regular expression represented by the ERE constant shall be the sequence of all unescaped characters and values of escape sequences between, but not including, the two delimiting <slash> characters.
7. A <blank> shall have no effect, except to delimit lexical tokens or within STRING or ERE tokens.
8. The token NUMBER shall represent a numeric constant. Its form and numeric value shall either be equivalent to the decimal-floating- constant token as specified by the ISO C standard, or it shall be a sequence of decimal digits and shall be evaluated as an integer constant in decimal. In addition, implementations may accept numeric constants with the form and numeric value equivalent to the hexadecimal-constant and hexadecimal-floating-constant tokens as specified by the ISO C standard.
If the value is too large or too small to be representable (see Section 1.1.2, Concepts Derived from the ISO C Standard), the behavior is undefined.
9. A sequence of underscores, digits, and alphabetics from the portable character set (see the Base Definitions volume of POSIX.1‐2017, Section 6.1, Portable Character Set), beginning with an <underscore> or alphabetic character, shall be considered a word.
10. The following words are keywords that shall be recognized as individual tokens; the name of the token is the same as the keyword:
BEGIN      delete     END        function   in         printf break      do         exit       getline    next       return continue   else       for        if         print      while
11. The following words are names of built-in functions and shall be recognized as the token BUILTIN_FUNC_NAME:
atan2     gsub      log       split     sub       toupper close     index     match     sprintf   substr cos       int       rand      sqrt      system exp       length    sin       srand     tolower
The above-listed keywords and names of built-in functions are considered reserved words.
12. The token NAME shall consist of a word that is not a keyword or a name of a built-in function and is not followed immediately (without any delimiters) by the '(' character.
13. The token FUNC_NAME shall consist of a word that is not a keyword or a name of a built-in function, followed immediately (without any delimiters) by the '(' character. The '(' character shall not be included as part of the token.
14. The following two-character sequences shall be recognized as the named tokens:
┌───────────┬──────────┬────────────┬──────────┐ │Token Name │ Sequence │ Token Name │ Sequence │ ├───────────┼──────────┼────────────┼──────────┤ │ADD_ASSIGN │    +=    │ NO_MATCH   │    !~    │ │SUB_ASSIGN │    -=    │ EQ         │    ==    │ │MUL_ASSIGN │    *=    │ LE         │    <=    │ │DIV_ASSIGN │    /=    │ GE         │    >=    │ │MOD_ASSIGN │    %=    │ NE         │    !=    │ │POW_ASSIGN │    ^=    │ INCR       │    ++    │ │OR         │    ||    │ DECR       │    --    │ │AND        │    &&    │ APPEND     │    >>    │ └───────────┴──────────┴────────────┴──────────┘ 15. The following single characters shall be recognized as tokens whose names are the character:
<newline> { } ( ) [ ] , ; + - * % ^ ! > < | ? : ~ $ =
There is a lexical ambiguity between the token ERE and the tokens '/' and DIV_ASSIGN.  When an input sequence begins with a <slash> character in any syntactic context where the token '/' or DIV_ASSIGN could appear as the next token in a valid program, the longer of those two tokens that can be recognized shall be recognized. In any other syntactic context where the token ERE could appear as the next token in a valid program, the token ERE shall be recognized.
0    All input files were processed successfully.
The exit status can be altered within the program by using an exit expression.
If any file operand is specified and the named file cannot be accessed, awk shall write a diagnostic message to standard error and terminate without any further action.
If the program specified by either the program operand or a progfile operand is not a valid awk program (as specified in the EXTENDED DESCRIPTION section), the behavior is undefined.
The index, length, match, and substr functions should not be confused with similar functions in the ISO C standard; the awk versions deal with characters, while the ISO C standard deals with bytes.
Because the concatenation operation is represented by adjacent expressions rather than an explicit operator, it is often necessary to use parentheses to enforce the proper evaluation precedence.
When using awk to process pathnames, it is recommended that LC_ALL, or at least LC_CTYPE and LC_COLLATE, are set to POSIX or C in the environment, since pathnames can contain byte sequences that do not form valid characters in some locales, in which case the utility's behavior would be undefined. In the POSIX locale each byte is a valid single-byte character, and therefore this problem is avoided.
On implementations where the "==" operator checks if strings collate equally, applications needing to check whether strings are identical can use:
length(a) == length(b) && index(a,b) == 1
On implementations where the "==" operator checks if strings are identical, applications needing to check whether strings collate equally can use:
a <= b && a >= b
The awk program specified in the command line is most easily specified within single-quotes (for example, 'program') for applications using sh, because awk programs commonly contain characters that are special to the shell, including double-quotes. In the cases where an awk program contains single-quote characters, it is usually easiest to specify most of the program as strings within single-quotes concatenated by the shell with quoted single-quote characters. For example:
awk '/'\''/ { print "quote:", $0 }'
prints all lines from the standard input containing a single-quote character, prefixed with quote:.
The following are examples of simple awk programs:
1. Write to the standard output all input lines for which field 3 is greater than 5:
$3 > 5
2. Write every tenth line:
(NR % 10) == 0
3. Write any line with a substring matching the regular expression:
/(G|D)(2[0-9][[:alpha:]]*)/
4. Print any line with a substring containing a 'G' or 'D', followed by a sequence of digits and characters. This example uses character classes digit and alpha to match language-independent digit and alphabetic characters respectively:
/(G|D)([[:digit:][:alpha:]]*)/
5. Write any line in which the second field matches the regular expression and the fourth field does not:
$2 ~ /xyz/ && $4 !~ /xyz/
6. Write any line in which the second field contains a <backslash>:
$2 ~ /\\/
7. Write any line in which the second field contains a <backslash>. Note that <backslash>-escapes are interpreted twice; once in lexical processing of the string and once in processing the regular expression:
$2 ~ "\\\\"
8. Write the second to the last and the last field in each line. Separate the fields by a <colon>:
{OFS=":";print $(NF-1), $NF}
9. Write the line number and number of fields in each line. The three strings representing the line number, the <colon>, and the number of fields are concatenated and that string is written to standard output:
{print NR ":" NF}
10. Write lines longer than 72 characters:
length($0) > 72
11. Write the first two fields in opposite order separated by OFS:
{ print $2, $1 }
12. Same, with input fields separated by a <comma> or <space> and <tab> characters, or both:
BEGIN { FS = ",[ \t]*|[ \t]+" } { print $2, $1 }
13. Add up the first column, print sum, and average:
{s += $1 } END   {print "sum is ", s, " average is", s/NR}
14. Write fields in reverse order, one per line (many lines out for each line in):
{ for (i = NF; i > 0; --i) print $i }
15. Write all lines between occurrences of the strings start and stop:
/start/, /stop/
16. Write all lines whose first field is different from the previous one:
$1 != prev { print; prev = $1 }
17. Simulate echo:
BEGIN  { for (i = 1; i < ARGC; ++i) printf("%s%s", ARGV[i], i==ARGC-1?"\n":" ") }
18. Write the path prefixes contained in the PATH environment variable, one per line:
BEGIN  { n = split (ENVIRON["PATH"], path, ":") for (i = 1; i <= n; ++i) print path[i] }
19. If there is a file named input containing page headers of the form: Page #
and a file named program that contains:
/Page/   { $2 = n++; } { print }
then the command line:
awk -f program n=5 input
prints the file input, filling in page numbers starting at 5.
This description is based on the new awk, ``nawk'', (see the referenced The AWK Programming Language), which introduced a number of new features to the historical awk:
1. New keywords: delete, do, function, return
2. New built-in functions: atan2, close, cos, gsub, match, rand, sin, srand, sub, system
3. New predefined variables: FNR, ARGC, ARGV, RSTART, RLENGTH, SUBSEP
4. New expression operators: ?, :, ,, ^
5. The FS variable and the third argument to split, now treated as extended regular expressions.
6. The operator precedence, changed to more closely match the C language.  Two examples of code that operate differently are:
while ( n /= 10 > 1) ... if (!"wk" ~ /bwk/) ...
Several features have been added based on newer implementations of awk:
*  Multiple instances of -f progfile are permitted.
*  The new option -v assignment.
*  The new predefined variable ENVIRON.
*  New built-in functions toupper and tolower.
*  More formatting capabilities are added to printf to match the ISO C standard.
Earlier versions of this standard required implementations to support multiple adjacent <semicolon>s, lines with one or more <semicolon> before a rule (pattern-action pairs), and lines with only <semicolon>(s).  These are not required by this standard and are considered poor programming practice, but can be accepted by an implementation of awk as an extension.
The overall awk syntax has always been based on the C language, with a few features from the shell command language and other sources. Because of this, it is not completely compatible with any other language, which has caused confusion for some users. It is not the intent of the standard developers to address such issues. A few relatively minor changes toward making the language more compatible with the ISO C standard were made; most of these changes are based on similar changes in recent implementations, as described above. There remain several C-language conventions that are not in awk.  One of the notable ones is the <comma> operator, which is commonly used to specify multiple expressions in the C language for statement. Also, there are various places where awk is more restrictive than the C language regarding the type of expression that can be used in a given context. These limitations are due to the different features that the awk language does provide.
Regular expressions in awk have been extended somewhat from historical implementations to make them a pure superset of extended regular expressions, as defined by POSIX.1‐2008 (see the Base Definitions volume of POSIX.1‐2017, Section 9.4, Extended Regular Expressions).  The main extensions are internationalization features and interval expressions. Historical implementations of awk have long supported <backslash>-escape sequences as an extension to extended regular expressions, and this extension has been retained despite inconsistency with other utilities. The number of escape sequences recognized in both extended regular expressions and strings has varied (generally increasing with time) among implementations. The set specified by POSIX.1‐2008 includes most sequences known to be supported by popular implementations and by the ISO C standard. One sequence that is not supported is hexadecimal value escapes beginning with '\x'.  This would allow values expressed in more than 9 bits to be used within awk as in the ISO C standard. However, because this syntax has a non-deterministic length, it does not permit the subsequent character to be a hexadecimal digit. This limitation can be dealt with in the C language by the use of lexical string concatenation. In the awk language, concatenation could also be a solution for strings, but not for extended regular expressions (either lexical ERE tokens or strings used dynamically as regular expressions). Because of this limitation, the feature has not been added to POSIX.1‐2008.
When a string variable is used in a context where an extended regular expression normally appears (where the lexical token ERE is used in the grammar) the string does not contain the literal <slash> characters.
Some versions of awk allow the form:
func name(args, ... ) { statements }
This has been deprecated by the authors of the language, who asked that it not be specified.
Historical implementations of awk produce an error if a next statement is executed in a BEGIN action, and cause awk to terminate if a next statement is executed in an END action. This behavior has not been documented, and it was not believed that it was necessary to standardize it.
The specification of conversions between string and numeric values is much more detailed than in the documentation of historical implementations or in the referenced The AWK Programming Language. Although most of the behavior is designed to be intuitive, the details are necessary to ensure compatible behavior from different implementations. This is especially important in relational expressions since the types of the operands determine whether a string or numeric comparison is performed. From the perspective of an application developer, it is usually sufficient to expect intuitive behavior and to force conversions (by adding zero or concatenating a null string) when the type of an expression does not obviously match what is needed. The intent has been to specify historical practice in almost all cases. The one exception is that, in historical implementations, variables and constants maintain both string and numeric values after their original value is converted by any use. This means that referencing a variable or constant can have unexpected side-effects. For example, with historical implementations the following program:
{ a = "+2" b = 2 if (NR % 2) c = a + b if (a == b) print "numeric comparison" else print "string comparison" }
would perform a numeric comparison (and output numeric comparison) for each odd-numbered line, but perform a string comparison (and output string comparison) for each even-numbered line. POSIX.1‐2008 ensures that comparisons will be numeric if necessary. With historical implementations, the following program:
BEGIN { OFMT = "%e" print 3.14 OFMT = "%f" print 3.14 }
would output "3.140000e+00" twice, because in the second print statement the constant "3.14" would have a string value from the previous conversion. POSIX.1‐2008 requires that the output of the second print statement be "3.140000".  The behavior of historical implementations was seen as too unintuitive and unpredictable.
It was pointed out that with the rules contained in early drafts, the following script would print nothing:
BEGIN { y[1.5] = 1 OFMT = "%e" print y[1.5] }
Therefore, a new variable, CONVFMT, was introduced. The OFMT variable is now restricted to affecting output conversions of numbers to strings and CONVFMT is used for internal conversions, such as comparisons or array indexing. The default value is the same as that for OFMT, so unless a program changes CONVFMT (which no historical program would do), it will receive the historical behavior associated with internal string conversions.
The POSIX awk lexical and syntactic conventions are specified more formally than in other sources. Again the intent has been to specify historical practice. One convention that may not be obvious from the formal grammar as in other verbal descriptions is where <newline> characters are acceptable. There are several obvious placements such as terminating a statement, and a <backslash> can be used to escape <newline> characters between any lexical tokens. In addition, <newline> characters without <backslash> characters can follow a comma, an open brace, a logical AND operator ("&&"), a logical OR operator ("||"), the do keyword, the else keyword, and the closing parenthesis of an if, for, or while statement. For example:
{ print $1, $2 }
The requirement that awk add a trailing <newline> to the program argument text is to simplify the grammar, making it match a text file in form. There is no way for an application or test suite to determine whether a literal <newline> is added or whether awk simply acts as if it did.
POSIX.1‐2008 requires several changes from historical implementations in order to support internationalization. Probably the most subtle of these is the use of the decimal-point character, defined by the LC_NUMERIC category of the locale, in representations of floating-point numbers. This locale-specific character is used in recognizing numeric input, in converting between strings and numeric values, and in formatting output. However, regardless of locale, the <period> character (the decimal-point character of the POSIX locale) is the decimal-point character recognized in processing awk programs (including assignments in command line arguments). This is essentially the same convention as the one used in the ISO C standard. The difference is that the C language includes the setlocale() function, which permits an application to modify its locale. Because of this capability, a C application begins executing with its locale set to the C locale, and only executes in the environment- specified locale after an explicit call to setlocale().  However, adding such an elaborate new feature to the awk language was seen as inappropriate for POSIX.1‐2008. It is possible to execute an awk program explicitly in any desired locale by setting the environment in the shell.
The undefined behavior resulting from NULs in extended regular expressions allows future extensions for the GNU gawk program to process binary data.
The behavior in the case of invalid awk programs (including lexical, syntactic, and semantic errors) is undefined because it was considered overly limiting on implementations to specify. In most cases such errors can be expected to produce a diagnostic and a non-zero exit status. However, some implementations may choose to extend the language in ways that make use of certain invalid constructs. Other invalid constructs might be deemed worthy of a warning, but otherwise cause some reasonable behavior. Still other constructs may be very difficult to detect in some implementations.  Also, different implementations might detect a given error during an initial parsing of the program (before reading any input files) while others might detect it when executing the program after reading some input. Implementors should be aware that diagnosing errors as early as possible and producing useful diagnostics can ease debugging of applications, and thus make an implementation more usable.
The unspecified behavior from using multi-character RS values is to allow possible future extensions based on extended regular expressions used for record separators. Historical implementations take the first character of the string and ignore the others.
Unspecified behavior when split(string,array,<null>) is used is to allow a proposed future extension that would split up a string into an array of individual characters.
In the context of the getline function, equally good arguments for different precedences of the | and < operators can be made. Historical practice has been that:
getline < "a" "b"
is parsed as:
( getline < "a" ) "b"
although many would argue that the intent was that the file ab should be read. However:
getline < "x" + 1
parses as:
getline < ( "x" + 1 )
Similar problems occur with the | version of getline, particularly in combination with $.  For example:
$"echo hi" | getline
(This situation is particularly problematic when used in a print statement, where the |getline part might be a redirection of the print.)
Since in most cases such constructs are not (or at least should not) be used (because they have a natural ambiguity for which there is no conventional parsing), the meaning of these constructs has been made explicitly unspecified. (The effect is that a conforming application that runs into the problem must parenthesize to resolve the ambiguity.)  There appeared to be few if any actual uses of such constructs.
Grammars can be written that would cause an error under these circumstances. Where backwards-compatibility is not a large consideration, implementors may wish to use such grammars.
Some historical implementations have allowed some built-in functions to be called without an argument list, the result being a default argument list chosen in some ``reasonable'' way. Use of length as a synonym for length($0) is the only one of these forms that is thought to be widely known or widely used; this particular form is documented in various places (for example, most historical awk reference pages, although not in the referenced The AWK Programming Language) as legitimate practice. With this exception, default argument lists have always been undocumented and vaguely defined, and it is not at all clear how (or if) they should be generalized to user-defined functions. They add no useful functionality and preclude possible future extensions that might need to name functions without calling them. Not standardizing them seems the simplest course. The standard developers considered that length merited special treatment, however, since it has been documented in the past and sees possibly substantial use in historical programs.  Accordingly, this usage has been made legitimate, but Issue 5 removed the obsolescent marking for XSI-conforming implementations and many otherwise conforming applications depend on this feature.
In sub and gsub, if repl is a string literal (the lexical token STRING), then two consecutive <backslash> characters should be used in the string to ensure a single <backslash> will precede the <ampersand> when the resultant string is passed to the function. (For example, to specify one literal <ampersand> in the replacement string, use gsub(ERE, "\\&").)
Historically, the only special character in the repl argument of sub and gsub string functions was the <ampersand> ('&') character and preceding it with the <backslash> character was used to turn off its special meaning.
The description in the ISO POSIX‐2:1993 standard introduced behavior such that the <backslash> character was another special character and it was unspecified whether there were any other special characters. This description introduced several portability problems, some of which are described below, and so it has been replaced with the more historical description. Some of the problems include:
*  Historically, to create the replacement string, a script could use gsub(ERE, "\\&"), but with the ISO POSIX‐2:1993 standard wording, it was necessary to use gsub(ERE, "\\\\&").  The <backslash> characters are doubled here because all string literals are subject to lexical analysis, which would reduce each pair of <backslash> characters to a single <backslash> before being passed to gsub.
*  Since it was unspecified what the special characters were, for portable scripts to guarantee that characters are printed literally, each character had to be preceded with a <backslash>.  (For example, a portable script had to use gsub(ERE, "\\h\\i") to produce a replacement string of "hi".)
The description for comparisons in the ISO POSIX‐2:1993 standard did not properly describe historical practice because of the way numeric strings are compared as numbers. The current rules cause the following code:
if (0 == "000") print "strange, but true" else print "not true"
to do a numeric comparison, causing the if to succeed. It should be intuitively obvious that this is incorrect behavior, and indeed, no historical implementation of awk actually behaves this way.
To fix this problem, the definition of numeric string was enhanced to include only those values obtained from specific circumstances (mostly external sources) where it is not possible to determine unambiguously whether the value is intended to be a string or a numeric.
Variables that are assigned to a numeric string shall also be treated as a numeric string. (For example, the notion of a numeric string can be propagated across assignments.) In comparisons, all variables having the uninitialized value are to be treated as a numeric operand evaluating to the numeric value zero.
Uninitialized variables include all types of variables including scalars, array elements, and fields. The definition of an uninitialized value in Variables and Special Variables is necessary to describe the value placed on uninitialized variables and on fields that are valid (for example, < $NF) but have no characters in them and to describe how these variables are to be used in comparisons. A valid field, such as $1, that has no characters in it can be obtained from an input line of "\t\t" when FS='\t'.  Historically, the comparison ($1<10) was done numerically after evaluating $1 to the value zero.
The phrase ``... also shall have the numeric value of the numeric string'' was removed from several sections of the ISO POSIX‐2:1993 standard because is specifies an unnecessary implementation detail. It is not necessary for POSIX.1‐2008 to specify that these objects be assigned two different values.  It is only necessary to specify that these objects may evaluate to two different values depending on context.
Historical implementations of awk did not parse hexadecimal integer or floating constants like "0xa" and "0xap0".  Due to an oversight, the 2001 through 2004 editions of this standard required support for hexadecimal floating constants. This was due to the reference to atof().  This version of the standard allows but does not require implementations to use atof() and includes a description of how floating-point numbers are recognized as an alternative to match historic behavior. The intent of this change is to allow implementations to recognize floating-point constants according to either the ISO/IEC 9899:1990 standard or ISO/IEC 9899:1999 standard, and to allow (but not require) implementations to recognize hexadecimal integer constants.
Historical implementations of awk did not support floating-point infinities and NaNs in numeric strings; e.g., "-INF" and "NaN".  However, implementations that use the atof() or strtod() functions to do the conversion picked up support for these values if they used a ISO/IEC 9899:1999 standard version of the function instead of a ISO/IEC 9899:1990 standard version. Due to an oversight, the 2001 through 2004 editions of this standard did not allow support for infinities and NaNs, but in this revision support is allowed (but not required). This is a silent change to the behavior of awk programs; for example, in the POSIX locale the expression:
("-INF" + 0 < 0)
formerly had the value 0 because "-INF" converted to 0, but now it may have the value 0 or 1.
A future version of this standard may require the "!=" and "==" operators to perform string comparisons by checking if the strings are identical (and not by checking if they collate equally).
Section 1.3, Grammar Conventions, grep, lex, sed
The Base Definitions volume of POSIX.1‐2017, Chapter 5, File Format Notation, Section 6.1, Portable Character Set, Chapter 8, Environment Variables, Chapter 9, Regular Expressions, Section 12.2, Utility Syntax Guidelines
The System Interfaces volume of POSIX.1‐2017, atof(), exec, isspace(), popen(), setlocale(), strtod()
LOGIN(1)                     General Commands Manual                    LOGIN(1)
login - rozpoczyna sesję pracy w systemie
login login [-p] [użytkownik] [ENV=wart  ...] login [-p] [-h host] [-f użytkownik] login [-p] -r host
login służy do utworzenia nowej sesji pracy z systemem. Zwykle wywoływane jest automatycznie w odpowiedzi na zachętę login: na terminalu użytkownika.  login może być specyficzne dla powłoki i może zostać wywołane jako podproces.  Najczęściej, login traktowane jest przez powłokę jako exec login, co powoduje opuszczenie przez użytkownika bieżącej powłoki.  Próba wykonania login z powłoki innej niż zgłoszeniowa powoduje komunikat o błędzie.
Przy wywołaniu polecenia z zachęty login:, użytkownik może po swojej nazwie wprowadzić zmienne środowiska. Zmienne te wprowadzane są w postaci: ZMIENNA=wartość. Nie wszystkie zmienne mogą jednak być ustawione w ten sposób, szczególnie PATH, HOME i SHELL.  Dodatkowo, zakazane może być IFS (input field separator: separator pól wejściowych), jeżeli powłoką zgłoszeniową użytkownika /bin/sh.
Użytkownik pytany jest o hasło, jeśli takowe istnieje.  Dla zapobieżenia ujawnieniu hasła wyświetlanie wprowadzanych znaków jest wyłączone. Dozwolona jest jedynie niewielka liczba nieudanych prób podania hasła. Po wyczerpaniu limitu prób login kończy pracę zaś połączenie komunikacyjne jest zrywane.
Jeżeli dla twego konta włączona jest kontrola ważności hasła, możesz być proszony o podanie nowego hasła przed kontynuacją. Będziesz wówczas musiał podać stare i nowe hasło. Więcej informacji na ten temat znajdziesz w passwd (1).
Po poprawnym rozpoczęciu sesji (zalogowaniu się), zostanie wyświetlona wiadomość dnia (jeśli jest) i informacja o stanie skrzynki pocztowej. Możesz wyłączyć wyświetlanie zawartości pliku wiadomości dnia, /etc/motd, tworząc zerowej wielkości plik .hushlogin w swoim katalogu domowym. Informacja o stanie skrzynki pocztowej jest jedną z: "You have new mail." (masz nową pocztę), "You have mail." (masz pocztę), lub "No Mail." (brak poczty) - stosownie do stanu skrzynki.
Identyfikator użytkownika i grupy (UID i GID) zostaną ustawione według wartości w pliku /etc/passwd.  Wartości $HOME, $SHELL, $PATH, $LOGNAME i $MAIL ustawiane są stosownie do odpowiednich pól danego wpisu pliku haseł.  Mogą być ustalane również wartości ulimit, umask oraz nice według wpisów w polu GECOS.
W niektórych systemach zostanie ustawiona zmienna środowiskowa $TERM, wskazująca na typ terminala na linii tty, jak podano w /etc/ttytype.
Może także zostać wykonany skrypt startowy (inicjacyjny) twojego interpretatora poleceń.  Przeglądnij, proszę, odpowiednią sekcję dokumentacji opisującą bardziej szczegółowo tę funkcję.
Login podsystemowy wskazywany jest obecnością "*" jako pierwszego znaku powłoki zgłoszeniowej.  Zadany katalog domowy zostanie użyty jako korzeń nowego systemu plików, do którego użytkownik jest faktycznie zalogowany.
-p     Zachowuje dotychczasowe środowisko.
-f     Nie dokonuje uwierzytelniania, użytkownik jest wstępnie uwierzytelniony.
-h     Nazwa zdalnej maszyny dla tego logowania.
-r     Wykonuje protokół autologin dla rlogin.
Opcje -r -h i -f stosowane są tylko wtedy, gdy login wywoływane jest przez roota.
Niniejsza wersja login posiada wiele opcji kompilacji, z których tylko część będzie mieć zastosowanie w danej instalacji.
Położenie plików może być różne w zależności od konfiguracji systemu.
/etc/utmp - lista bieżących sesji pracy /etc/wtmp - lista poprzednich sesji pracy /etc/passwd - informacja o kontach użytkowników /etc/shadow - zakodowane hasła i informacja o ich ważności /etc/motd - plik 'wiadomości dnia' /etc/nologin - zapobiega logowaniu innych niż root /etc/ttytype - lista typów terminali $HOME/.profile - skrypt startowy domyślnej powłoki $HOME/.hushlogin - zapobiega m.in. wyświetlaniu wiadomości dnia
getty(8), mail(1), passwd(1), sh(1), su(1), login.defs(5), passwd(5), nologin(5)
Julianne Frances Haugh (jockgrrl@ix.netcom.com)
Niniejsza dokumentacja opisuje polecenie wchodzące w skład pakietu shadow-password.  Z uwagi na powtarzające się nazwy poleceń, upewnij się, że korzystasz z właściwej dokumentacji.
i3lock(1)                         User Manuals                         i3lock(1)
i3lock - improved screen locker
i3lock [-v] [-n] [-b] [-i image.png] [-c color] [-t] [-p pointer] [-u] [-e] [-f]
i3lock is a simple screen locker like slock. After starting it, you will see a white screen (you can configure the color/an image). You can return to your screen by entering your password.
• i3lock forks, so you can combine it with an alias to suspend to RAM (run "i3lock && echo mem > /sys/power/state" to get a locked screen after waking up your computer from suspend to RAM)
• You can specify either a background color or a PNG image which will be displayed while your screen is locked.
• You can specify whether i3lock should bell upon a wrong password.
• i3lock uses PAM and therefore is compatible with LDAP, etc.
-v, --version Display the version of your i3lock
-n, --nofork Don't fork after starting.
-b, --beep Enable beeping. Be sure to not do this when you are about to annoy other people, like when opening your laptop in a boring lecture.
-u, --no-unlock-indicator Disable the unlock indicator. i3lock will by default show an unlock indicator after pressing keys. This will give feedback for every keypress and it will show you the current PAM state (whether your password is currently being verified or whether it is wrong).
-i path, --image=path Display the given PNG image instead of a blank screen.
--raw=format Read the image given by --image as a raw image instead of PNG. The argument is the image's format as <width>x<height>:<pixfmt>. The supported pixel formats are: ´native', 'rgb', 'xrgb', 'rgbx', 'bgr', 'xbgr', and 'bgrx'.  The "native" pixel format expects a pixel as a 32-bit (4-byte) integer in the machine's native endianness, with the upper 8 bits unused. Red, green and blue are stored in the remaining bits, in that order.
Example: --raw=1920x1080:rgb
You can use ImageMagick’s convert(1) program to feed raw images into i3lock:
convert wallpaper.jpg RGB:- | i3lock --raw 3840x2160:rgb --image /dev/stdin
This allows you to load a variety of image formats without i3lock having to support each one explicitly.
-c rrggbb, --color=rrggbb Turn the screen into the given color instead of white. Color must be given in 3-byte format: rrggbb (i.e. ff0000 is red).
-t, --tiling If an image is specified (via -i) it will display the image tiled all over the screen (if it is a multi-monitor setup, the image is visible on all screens).
-p win|default, --pointer=win|default If you specify "default", i3lock does not hide your mouse pointer. If you specify "win", i3lock displays a hardcoded Windows-Pointer (thus enabling you to mess with your friends by using a screenshot of a Windows desktop as a locking-screen).
-e, --ignore-empty-password When an empty password is provided by the user, do not validate it. Without this option, the empty password will be provided to PAM and, if invalid, the user will have to wait a few seconds before another try. This can be useful if the XF86ScreenSaver key is used to put a laptop to sleep and bounce on resume or if you happen to wake up your computer with the enter key.
-f, --show-failed-attempts Show the number of failed attempts, if any.
--debug Enables debug logging.  Note, that this will log the password used for authentication to stdout.
The -d (--dpms) option was removed from i3lock in version 2.8. There were plenty of use-cases that were not properly addressed, and plenty of bugs surrounding that feature. While features are not normally removed from i3 and its tools, we felt the need to make an exception in this case.
Users who wish to explicitly enable DPMS only when their screen is locked can use a wrapper script around i3lock like the following:
#!/bin/sh revert() { xset dpms 0 0 0 } trap revert HUP INT TERM xset +dpms dpms 5 5 5 i3lock -n revert
The -I (--inactivity-timeout=seconds) was removed because it only makes sense with DPMS.
xautolock(1) - use i3lock as your screen saver
convert(1) - feed a wide variety of image formats to i3lock
Michael Stapelberg <michael+i3lock at stapelberg dot de>
Jan-Erik Rediger <badboy at archlinux.us>
RECSEL(1)                         User Commands                        RECSEL(1)
recsel - print records from a recfile
recsel [OPTION]... [-t TYPE] [-j FIELD] [-n INDEXES | -e RECORD_EXPR | -q STR | -m NUM] [-c | (-p|-P) FIELD_EXPR] [FILE]...
Select and print rec data.
-d, --include-descriptors print record descriptors along with the matched records.
-C, --collapse do not section the result in records with newlines.
-S, --sort=FIELD,... sort the output by the specified fields.
-G, --group-by=FIELD,... group records by the specified fields.
-U, --uniq remove duplicated fields in the output records.
-s, --password=STR decrypt confidential fields with the given password.
--help print a help message and exit.
--version show version and exit.
Record selection options: -i, --case-insensitive make strings case-insensitive in selection expressions.
-t, --type=TYPE operate on records of the specified type only.
-e, --expression=RECORD_EXPR selection expression.