Data is stored or generated in various formats but for a human, reading tabular data in a table format is often desired. Depending on your data, there are different options
CSV
If the data is in CSV format, csvlook from csvkit is a good option.
Let’s say we have the following CSV file:
cat username.csv
Username;Identifier;First name;Last name
booker12;9012;Rachel;Booker
grey07;2070;Laura;Grey
johnson81;4081;Craig;Johnson
jenkins46;9346;Mary;Jenkins
smith79;5079;Jamie;Smith
When we output it with csvlook, we have much better experience
csvlook username.csv
| Username | Identifier | First name | Last name |
| --------- | ---------- | ---------- | --------- |
| booker12 | 9 012 | Rachel | Booker |
| grey07 | 2 070 | Laura | Grey |
| johnson81 | 4 081 | Craig | Johnson |
| jenkins46 | 9 346 | Mary | Jenkins |
| smith79 | 5 079 | Jamie | Smith |
Generic approach
column is a utility tool that outputs given data in column format. Using the -t
flag, the data is output in table format. It defaults to splitting at whitespace but it can be customised with -s [delimiter]
flag.
Let’s say we have some version data like this
cat demo.txt
aom (3.10.0) < 3.11.0
atuin (18.3.0) < 18.4.0
automake (1.16.5) < 1.17
bat (0.24.0_1) < 0.24.0_2
bdw-gc (8.2.6) < 8.2.8
boost@1.85 (1.85.0) < 1.85.0_2
oven-sh/bun/bun (1.1.38) < 1.1.42
cloc (2.00) < 2.02
cmake (3.29.6) < 3.31.3
we can format it with
cat demo | column -t
aom (3.10.0) < 3.11.0
atuin (18.3.0) < 18.4.0
automake (1.16.5) < 1.17
bat (0.24.0_1) < 0.24.0_2
bdw-gc (8.2.6) < 8.2.8
boost@1.85 (1.85.0) < 1.85.0_2
oven-sh/bun/bun (1.1.38) < 1.1.42
cloc (2.00) < 2.02
cmake (3.29.6) < 3.31.3
Depending on which version of column
you have, you maybe able provide column headers with -N
flag:
cat demo | column -t -N PACKAGE,CURRENT,_,LATEST
PACKAGE CURRENT _ LATEST
aom (3.10.0) < 3.11.0
atuin (18.3.0) < 18.4.0
automake (1.16.5) < 1.17
bat (0.24.0_1) < 0.24.0_2
bdw-gc (8.2.6) < 8.2.8
boost@1.85 (1.85.0) < 1.85.0_2
oven-sh/bun/bun (1.1.38) < 1.1.42
cloc (2.00) < 2.02
cmake (3.29.6) < 3.31.3
Note
-N
flag does not work with thecolumn
command that ships with macos.
Tip
Did you know you can subscribe to GitHub commits via RSS? It’s very handy for TIL repositories for learning cool stuff daily.
I learned about
command
from Veronica Explains’ Youtube video to which I found my way from Ryan Cheley’s TIL repository.