User Tools

Site Tools


pretty_print_csv_data

This is an old revision of the document!


bare bones solution

 | column -t -s,

Example:

$ cat mason.csv
transaction_id,seller_id,customer_id,customer_name,amount
739554149,456938,7196590,unknown,38.05
730159148,206741,0676350,foo,9.68
703679772,590474,0177317,barbie,0.7
670454639,528847,0582211,vicky,370.45
$ cat mason.csv | column -t -s,
transaction_id  seller_id  customer_id  customer_name  amount
739554149       456938     7196590      unknown        38.05
730159148       206741     0676350      foo            9.68
703679772       590474     0177317      barbie         0.7
670454639       528847     0582211      vicky          370.45

Tested on:

git bash 2.18.0 running on Windows 10 Enterprise

bash function

Add this to ~/.bashrc

# Pretty print csv data
# Sample usage:
# pretty_csv data.csv
# cat data.csv | pretty_csv
# pretty_csv < data.csv
function pretty_csv
{
  column -t -s, "$@"
}

Tested on:

git bash 2.18.0 running on Windows 10 Enterprise

See also:- https://www.stefaanlippens.net/pretty-csv.html - talks about handling corner cases and other OSes.

pretty_print_csv_data.1625253142.txt.gz · Last modified: 2021/07/02 19:12 by admin