(gawk.info.gz) Basic Printf

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