sankgq
Last Updated: February 25, 2016
·
2.51K
· pykler
88dcd9a1b56c02e905ac3a352e43ba81

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
Say Thanks
Respond

2 Responses
Add your response

5304
B3881a28fe402dd2d1de44717486cae8

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
88dcd9a1b56c02e905ac3a352e43ba81

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

over 1 year ago ·
Filed Under