Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  ultrasawblade Mar 29 '11 at 13:41
    
Well, more or less like it's shown in Excel. Having the columns aligned and properly spaced with proper underlining, if possible. –  vonhogen Mar 29 '11 at 15:48
add comment

4 Answers

up vote 5 down vote accepted

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

share|improve this answer
add comment

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
share|improve this answer
    
Use column -s, -t yourfile.csv. Whenever you see cat file | command consider command file or command < file first. –  RedGrittyBrick Apr 17 '11 at 7:44
    
Yes that's a fair point, I'll edit. –  8088 Apr 17 '11 at 7:46
add comment

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.)

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.