有人知道Linux/OS X的命令行CSV查看器吗?我在考虑一些更少的东西,但以一种更可读的方式分隔列。(我可以用OpenOffice Calc或Excel打开它,但这对于我需要查看的数据来说太强大了。)有水平和垂直滚动会很棒。
当前回答
如果你是一个vimmer,使用CSV插件,它非常漂亮:
.
其他回答
XSV不仅仅是一个查看器。我推荐它用于命令行上的大多数CSV任务,特别是在处理大型数据集时。
我写了这个csv_view.sh来从命令行格式化csv,这读取整个文件来找出每列的最佳宽度(需要perl,假设字段中没有逗号,也使用较少):
#!/bin/bash
perl -we '
sub max( @ ) {
my $max = shift;
map { $max = $_ if $_ > $max } @_;
return $max;
}
sub transpose( @ ) {
my @matrix = @_;
my $width = scalar @{ $matrix[ 0 ] };
my $height = scalar @matrix;
return map { my $x = $_; [ map { $matrix[ $_ ][ $x ] } 0 .. $height - 1 ] } 0 .. $width - 1;
}
# Read all lines, as arrays of fields
my @lines = map { s/\r?\n$//; [ split /,/ ] } ;
my $widths =
# Build a pack expression based on column lengths
join "",
# For each column get the longest length plus 1
map { 'A' . ( 1 + max map { length } @$_ ) }
# Get arrays of columns
transpose
@lines
;
# Format all lines with pack
map { print pack( $widths, @$_ ) . "\n" } @lines;
' $1 | less -NS
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)
如果你是一个vimmer,使用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]语法。
推荐文章
- 如何使用mongoimport导入CSV文件?
- 如何从另一个文件A中删除文件B中出现的行?
- 如何配置Mac OS X术语,使git有颜色?
- 对以制表符分隔的文件进行排序
- 使用sudo时未找到命令
- 当有命令行参数时,如何使用GDB分析程序的核心转储文件?
- 我如何确定文件编码在OS X?
- 使iTerm以与其他操作系统相同的方式翻译“元键”
- 错误:无法在ARM处理器上的Homebrew中安装英特尔默认前缀(/usr/local)
- 如何强制从另一个SSH会话分离屏幕?
- 如何将文件指针(file * fp)转换为文件描述符(int fd)?
- 在Mac OS X上哪里安装Android SDK ?
- Mac/OS X上的/var/lib/docker在哪里
- Linux Bash中双&和分号有什么区别?
- 如何合并2 JSON对象从2个文件使用jq?