GNU Info

Info Node: (gawk.info)Basic Printf

(gawk.info)Basic Printf


Next: Control Letters Prev: Printf Up: Printf
Enter node , (file) or (file)node

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 a redirection
(Note: Redirecting Output of `print' and `printf'.).

   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 when the message is printed.


automatically generated by info2www version 1.2.2.9