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


当前回答

看看csvkit。它提供了一组遵循UNIX哲学的工具(这意味着它们很小、简单、用途单一,并且可以组合使用)。

下面是一个例子,它从免费的Maxmind世界城市数据库中提取了德国人口最多的十个城市,并以控制台可读的格式显示结果:

$ csvgrep -e iso-8859-1 -c 1 -m "de" worldcitiespop | csvgrep -c 5 -r "\d+" 
  | csvsort -r -c 5 -l | csvcut -c 1,2,4,6 | head -n 11 | csvlook
-----------------------------------------------------
|  line_number | Country | AccentCity | Population  |
-----------------------------------------------------
|  1           | de      | Berlin     | 3398362     |
|  2           | de      | Hamburg    | 1733846     |
|  3           | de      | Munich     | 1246133     |
|  4           | de      | Cologne    | 968823      |
|  5           | de      | Frankfurt  | 648034      |
|  6           | de      | Dortmund   | 594255      |
|  7           | de      | Stuttgart  | 591688      |
|  8           | de      | Düsseldorf | 577139      |
|  9           | de      | Essen      | 576914      |
|  10          | de      | Bremen     | 546429      |
-----------------------------------------------------

Csvkit是平台独立的,因为它是用Python编写的。

其他回答

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)

安装csvtool(在Ubuntu上)

sudo apt-get install csvtool

然后运行:

csvtool readable filename | view -

这将使它在只读的vim实例中非常漂亮,即使您有一些具有非常长的值的单元格。

Tabulator包中的tblless包装了unix column命令,并且还对数值列进行对齐。

Tabview真的很好。工作200+MB的文件,显示很好,这是与LibreOffice的bug,以及在gvim的csv插件。

Anaconda版本可以在这里找到:https://anaconda.org/bioconda/tabview

奥弗里的回答会告诉你你想要的一切。 但. .如果你不想记住这个命令,你可以把它添加到你的~/。Bashrc(或同等):

csview()
{
local file="$1"
sed "s/,/\t/g" "$file" | less -S
}

这与Ofri的答案完全相同,除了我已经将它包装在一个shell函数中,并且使用less -S选项来停止行包装(使less的行为更像office/oocalc)。

打开一个新的shell(或者输入source ~/。Bashrc在你当前的shell),并运行命令使用:

csview < filename >