Pretty Print a CSV file
Have you ever had a csv (comma separated file) file that you wanted to see nicely and did not want to open up a spreadsheet editor just to be able to see it in a readable way. Well the following command works with most csv files and will do just that:
column -s, -t <tmp.csv
If you have commas within your data you might want to use the following longer but handy linux command:
python -c 'import sys,csv; c = csv.reader(sys.stdin); [sys.stdout.write("^M".join(map(repr,r))+"\n") for r in c];' <tmp.csv | column -s '^M' -t
Written by Hatem Nassrat
Related protips
2 Responses

In case you are using Emacs, csv-mode is incredibly handy and lets you not only view CSV properly, but also sort columns etc. I know this tip is about the command line, but for us Emcas users the editor is the command line ;-)
over 1 year ago
·

Some users live in emacs ... I prefer to live in a shell :)
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Linux
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#