sankgq
Last Updated: February 25, 2016
·
3.463K
· pykler

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

2 Responses
Add your response

5304

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 ·
5305

Some users live in emacs ... I prefer to live in a shell :)

over 1 year ago ·