Page tree

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.



awk also has a printf function, which can take the standard formatting commands (see

Code Block
awk 'BEGIN{ printf("%.2f %%\n", 100*6697/547664) }'


  • The printf arguments are enclosed in parentheses since it is a true function.
  • The 1st argument is the format string, enclosed in double quotes.
    • The %.2f format specifier says to output a floating point number with 2 digits after the decimal place.
    • The %% format specifier is used to output a single, literal percent sign.
    • Unlike the standard print statement, the printf function does not automaticlly append a newline to the output, so \n is added to the format string here.
  • Remaining arguments to printf are the values to be substituted for the format specifiers.
    • Here just our percentage computation