Skip to content
Justice Tech School

Printing Tables with printf

printf with widths aligns columns.

Example
printf "%-8s %5s\n" Name Score
printf "%-8s %5d\n" Ada 92 Kofi 78

Result

Name     Score
Ada         92
Kofi        78

Exercise

Left align width 8.

"%s"

Quiz Test

What does %-8s do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.