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:

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

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

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

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

  1. > Import-Csv .\people-example.csv.txt | Format-Table
  2.  
  3. First Name Last Name Country       age
  4. ---------- --------- -------       ---
  5. Bob        Smith     United States 24
  6. Alice      Williams  Canada        23
  7. Malcolm    Jone      England       22
  8. Felix      Brown     USA           23
  9. Alex       Cooper    Poland        23
  10. Tod        Campbell  United States 22
  11. Derek      Ward      Switzerland   25