An Awk Primer/A Digression: The sprintf Function

While "sprintf()" is a string function, it was not discussed with the other string functions, since its syntax is virtually identical to that of "printf()". In fact, "sprintf()" acts in exactly the same way as "printf()", except that "sprintf()" assigns its output to a variable, not standard output. For example:

   BEGIN {var = sprintf("[%8.3f]",3.141592654); print var}

—yields:

   [   3.142]