Unix command-Line CSV viewer

8

Is there a convenient command-line csv viewer, possibly a unix tool or a mod of some tools (e.g. vim or python)?

I find it easy to simply edit CSV files by writing it manually (since all you need to do it comma delimit the columns), but is there a way to view it in a slightly nicer UI on the command-line?

vonhogen

Posted 2011-03-29T13:21:08.737

Reputation: 1 949

Question was closed 2018-12-09T04:15:40.807

Can you be more specific on how you want the output formatted? CSV's are easily to manipulate with shell tools so there's likely a string of four or five shell commands that can format them any way you like for convenient viewing. – LawrenceC – 2011-03-29T13:41:33.330

Well, more or less like it's shown in Excel. Having the columns aligned and properly spaced with proper underlining, if possible. – vonhogen – 2011-03-29T15:48:07.737

Answers

5

sc is a command-line spreadsheet program that's been around a long time, likely available in your package manager. Here's a Linux Journal intro article to it:

http://www.linuxjournal.com/article/10699

Celsius1414

Posted 2011-03-29T13:21:08.737

Reputation: 84

1sc reads colon-delimited files, not CSV files: http://www.linuxjournal.com/article/10699?page=0,1 – Nathaniel M. Beaver – 2017-01-03T01:32:57.853

4

There's a tool, CSVfix, which helps with viewing CSV files.

CSVfix is a command-line stream editor specifically designed to deal with CSV data. With it you can, among other things:

  • Convert fixed format, multi-line and DSV files to CSV
  • Reorder, remove, split and merge fields
  • Convert case, trim leading & trailing spaces
  • Search for specific content using regular expressions
  • Filter out duplicate data or data on exclusion lists
  • Perform sed/perl style editing
  • Enrich with data from other sources
  • Add sequence numbers and file source information
  • Split large CSV files into smaller files based on field contents
  • Perform arithmetic calculations on individual fields
  • Validate CSV data against a collection of validation rules
  • Convert between CSV and fixed format, XML, SQL and DSV
  • Summarise CSV data, calculating averages, modes, frequencies etc.

A simple way to view CSV files on the command-line is to pipe the .csv file into the column utility with the column delimiter set as a comma:

column -s, -t yourfile.csv

Gaff

Posted 2011-03-29T13:21:08.737

Reputation: 16 863

1Use column -s, -t yourfile.csv. Whenever you see cat file | command consider command file or command < file first. – RedGrittyBrick – 2011-04-17T07:44:20.863

Yes that's a fair point, I'll edit. – Gaff – 2011-04-17T07:46:02.637

3

It seems like this question overlaps (at least partially) with my similar question on StackOverflow:

Command line CSV viewer?

The top answer there is currently:

column -s, -t < somefile.csv | less -#2 -N -S

(Please see the link for more details.)

Benjamin Oakes

Posted 2011-03-29T13:21:08.737

Reputation: 2 585

3

The powerful program vim have a plugin for .csv files in CSV Plugin and its screenshot is

enter image description here

shgnInc

Posted 2011-03-29T13:21:08.737

Reputation: 375

2

I know this question is already quite old, but I want to add another tool, which I found very convenient:

tabview (https://github.com/TabViewer/tabview)

The header line of the csv file will always stay at the top and there are many more features.

enter image description here

TabeaKischka

Posted 2011-03-29T13:21:08.737

Reputation: 133

1

emacs csv-nav mode will show the csv file and open single records in a text buffer for you to edit and save back to the original buffer

Prach459

Posted 2011-03-29T13:21:08.737

Reputation: 11