Join David D. Levine for an in-depth discussion in this video Formatting output with printf(), part of AWK Essential Training.
- View Offline
…In addition to the print statement, AWK…provides the function printf for formatted printing.…In this lesson, we'll use printf to output a file of names, email…addresses, and bowling averages, in a nice columnal format for a fixed width font.…You might do this to output the information…interactively, for easy reading in the terminal window.…The printf function in AWK has much the same…syntax as it does in the C programming language.…Printf takes one argument which is a format and a number…of arguments after that of values depending on the original format.…
The parentheses after printf are optional in AWK, but…in most circumstances it's a good practice to include them.…This function outputs zero or more values…in the format specified by its format argument.…Which is a single string containing format specifiers…that tell printf how to output the value arguments.…Each format specifier is matched to a value in order.…Here's the input file we'll be using for this lesson.…As you see, it is a comma separated file with…
In this course, award-winning author and teacher David D. Levine shows you how to use AWK to read and write data in a variety of formats, produce reports, and automate repetitive tasks. He reviews the nuts and bolts of the language, such as field separators, pattern matching, variables, operators, expressions, and control structures; functions available for manipulating data; and integration with other programs like Excel.
- What is AWK?
- Writing an AWK program
- Working with records, fields, patterns, and actions
- Specifying field and record separators with variables
- Using built-in and user-defined variables
- Building control structures
- Formatting output
- Manipulating string data with functions
- Scripting with AWK