有人知道Linux/OS X的命令行CSV查看器吗?我在考虑一些更少的东西,但以一种更可读的方式分隔列。(我可以用OpenOffice Calc或Excel打开它,但这对于我需要查看的数据来说太强大了。)有水平和垂直滚动会很棒。


当前回答

如果你是一个vimmer,使用CSV插件,它非常漂亮:

.

其他回答

你也可以用这个:

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

Column是一个标准的Unix程序,非常方便——它可以找到每列的适当宽度,并将文本显示为格式良好的表格。

注意:无论何时有空字段,都需要在其中放置某种占位符,否则该列将与后面的列合并。下面的例子演示了如何使用sed插入一个占位符:

$ cat data.csv
1,2,3,4,5
1,,,,5
$ sed 's/,,/, ,/g;s/,,/, ,/g' data.csv | column -s, -t
1  2  3  4  5
1           5
$ cat data.csv
1,2,3,4,5
1,,,,5
$ column -s, -t < data.csv
1  2  3  4  5
1  5
$ sed 's/,,/, ,/g;s/,,/, ,/g' data.csv | column -s, -t
1  2  3  4  5
1           5

注意,对,,,的替换做了两次。如果只做一次,1…4将变成1,,,4,因为第二个逗号已经匹配了。

Tabview:轻量级的python curses命令行CSV文件查看器(以及其他表格式python数据,如列表中的列表)在Github上

特点:

Python 2.7+, 3.x Unicode support Spreadsheet-like view for easily visualizing tabular data Vim-like navigation (h,j,k,l, g(top), G(bottom), 12G goto line 12, m - mark, ' - goto mark, etc.) Toggle persistent header row Dynamically resize column widths and gap Sort ascending or descending by any column. 'Natural' order sort for numeric values. Full-text search, n and p to cycle between search results 'Enter' to view the full cell contents Yank cell contents to clipboard F1 or ? for keybindings Can also use from python command line to visualize any tabular data (e.g. list-of-lists)

我为这些(和其他)目的创建了一个表。安装与

pip install tablign

and

$ cat test.csv
Header1,Header2,Header3
Pizza,Artichoke dip,Bob's Special of the Day
BLT,Ham on rye with the works,
$ tablign test.csv
Header1 , Header2                   , Header3
Pizza   , Artichoke dip             , Bob's Special of the Day
BLT     , Ham on rye with the works ,

如果数据由逗号以外的其他东西分隔,也适用。最重要的是,它保留了分隔符,因此您还可以使用它来设置ASCII表的样式,而不牺牲[Markdown,CSV,LaTeX]语法。

可以在全局安装nodejs包tecfu/tty-table,这样做:

apt-get install nodejs
npm i -g tty-table
cat data.csv | tty-table

它还可以处理流。

要了解更多信息,请参阅终端使用的文档。

在python中有一个简短的命令行脚本:https://github.com/rgrp/csv2ascii/blob/master/csv2ascii.py

只需下载并放置在您的路径。用法就像

csv2ascii.py [options] csv-file-path

转换csv文件在csv-file-path到ascii形式返回的结果 stdout。如果csv-file-path = '-'则从stdin读取。

选项:

  -h, --help            show this help message and exit
  -w WIDTH, --width=WIDTH
                        Width of ascii output
  -c COLUMNS, --columns=COLUMNS
                        Only display this number of columns