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


当前回答

XSV不仅仅是一个查看器。我推荐它用于命令行上的大多数CSV任务,特别是在处理大型数据集时。

其他回答

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)

XSV不仅仅是一个查看器。我推荐它用于命令行上的大多数CSV任务,特别是在处理大型数据集时。

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

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]语法。

这里有一个(可能太)简单的选择:

sed "s/,/\t/g" filename.csv | less

奥弗里的回答会告诉你你想要的一切。 但. .如果你不想记住这个命令,你可以把它添加到你的~/。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 >