Skip to content

printf format strings #4

@jesusff

Description

@jesusff

We saw this morning some examples of format strings to customize the output of the awk command using a printf statement followed by a special string. printf is also a standalone command to format text and numbers, and it relies on the printf function in the standard C language. Many other languages (Python, Java, R, ...) use these format strings.

printf (either standalone or from awk, Python, ...) can be used e.g. to pad an integer with zeros:

printf "%04d" 3
0003

Or to format floating point numbers:

printf "%6.4f" 3.1415926536
3.1416

To learn more about format strings, have a look at e.g. https://www.cprogramming.com/tutorial/printf-format-strings.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions