gawk: Basic Printf

1 
1 5.5.1 Introduction to the 'printf' Statement
1 --------------------------------------------
1 
1 A simple 'printf' statement looks like this:
1 
1      printf FORMAT, ITEM1, ITEM2, ...
1 
1 As for 'print', the entire list of arguments may optionally be enclosed
1 in parentheses.  Here too, the parentheses are necessary if any of the
1 item expressions uses the '>' relational operator; otherwise, it can be
1 confused with an output redirection (⇒Redirection).
1 
1    The difference between 'printf' and 'print' is the FORMAT argument.
1 This is an expression whose value is taken as a string; it specifies how
1 to output each of the other arguments.  It is called the "format
1 string".
1 
1    The format string is very similar to that in the ISO C library
1 function 'printf()'.  Most of FORMAT is text to output verbatim.
1 Scattered among this text are "format specifiers"--one per item.  Each
1 format specifier says to output the next item in the argument list at
1 that place in the format.
1 
1    The 'printf' statement does not automatically append a newline to its
1 output.  It outputs only what the format string specifies.  So if a
1 newline is needed, you must include one in the format string.  The
1 output separator variables 'OFS' and 'ORS' have no effect on 'printf'
1 statements.  For example:
1 
1      $ awk 'BEGIN {
1      >    ORS = "\nOUCH!\n"; OFS = "+"
1      >    msg = "Don\47t Panic!"
1      >    printf "%s\n", msg
1      > }'
1      -| Don't Panic!
1 
1 Here, neither the '+' nor the 'OUCH!' appears in the output message.
1