Chapter 12. Formatting and Reporting
To maximize usefulness, the data collected and analyzed previously must be presented in a clear format that is easy to understand. Standard command-line output is not often well formatted to present large amounts of information, but some techniques can be used to improve readability.
Commands in Use
In this chapter, we introduce tput to control formatting in the terminal.
tput
The tput command can be used to control formatting in the terminal such as cursor location and behavior. Note that tput is actually an extraction. The command looks up the terminal formatting codes in the terminfo database.
Common command parameters
- clear
-
Clear the screen
- cols
-
Print the number of terminal columns
- cup <x> <y>
-
Move the cursor to position <x> and <y>
- lines
-
Print the number of terminal lines
- rmcup
-
Restore the previously saved terminal layout
- setab
-
Set the terminal background color
- setaf
-
Set the terminal foreground color
- smcup
-
Save the current terminal layout and clear the screen
Formatting for Display and Print with HTML
Converting information to HTML is a great way to provide clean and clear formatting if you do not need to view it directly on the command line. This is also a good option if you ultimately want to print the information, as you can use the web browser’s built-in print capabilities.
The full syntax of HTML is beyond the scope of this book, but we will cover some of the basics. HTML is a computer language that is defined ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access