Quick tip: Column display

Submitted by Robert MacLean on Fri, 06/08/2018 - 09:15

When you work with delimited data (CSV, TSV etc...) it can be a pain to just see the data in a nice way, for example, this data:

> cat people-example.csv.txt
First Name,Last Name,Country,age
"Bob","Smith","United States",24
"Alice","Williams","Canada",23
"Malcolm","Jone","England",22
"Felix","Brown","USA",23
"Alex","Cooper","Poland",23
"Tod","Campbell","United States",22
"Derek","Ward","Switzerland",25

With Unix like OSs, you can use the column command to format the layout; for example:

> column -t -s',' people-example.csv.txt
First Name  Last Name   Country          age
"Bob"       "Smith"     "United States"  24
"Alice"     "Williams"  "Canada"         23
"Malcolm"   "Jone"      "England"        22
"Felix"     "Brown"     "USA"            23
"Alex"      "Cooper"    "Poland"         23
"Tod"       "Campbell"  "United States"  22
"Derek"     "Ward"      "Switzerland"    25

With Windows, you can use Import-CSV and Format-Table in PowerShell:

> Import-Csv .\people-example.csv.txt | Format-Table

First Name Last Name Country       age
---------- --------- -------       ---
Bob        Smith     United States 24
Alice      Williams  Canada        23
Malcolm    Jone      England       22
Felix      Brown     USA           23
Alex       Cooper    Poland        23
Tod        Campbell  United States 22
Derek      Ward      Switzerland   25