How to view CSV files in the terminal
There’s nothing better than a simple, one-line bash command utility to help you get the job done. For me, I wanted an easy way to just view a CSV file in the terminal. I didn’t need to edit anything; just wanted to be able to page through a file easily. Here’s a little snippet I found to do this:
column -s, -t < filename.csv | less -#2 -N -S;
And even better, as an alias:
alias csv='function _csv() { column -s, -t < "$1" | less -#2 -N -S; }; _csv'
Which can be used like csv filename.csv
.
Here’s what it does:
- It uses the
column
command to separate the file by commas and formats it in a table - Then uses the
less
command to show the result in a pageable format with text wrapping and line numbers
Of course if you need something more powerful with editing, you might be better off using something more robust like VisiData or the csv.vim vim plugin.