命令行CSV查看器? [英] Command line CSV viewer?

查看:118
本文介绍了命令行CSV查看器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人知道Linux / OS X的命令行CSV查看器?我正在想像,但是以更可读的方式空格的列。 (我会很好用OpenOffice Calc或Excel打开它,但是这太太强大,只是查看数据,像我需要的)。水平和垂直滚动将是伟大的。

Anyone know of a command-line CSV viewer for Linux/OS X? I'm thinking of something like less but that spaces out the columns in a more readable way. (I'd be fine with opening it with OpenOffice Calc or Excel, but that's way too overpowered for just looking at the data like I need to.) Having horizontal and vertical scrolling would be great.

推荐答案

您也可以使用:

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

是一个标准的unix程序,非常方便 - 它找到每个列的适当宽度,并将文本显示为格式正确的表格。

column is a standard unix program that is very convenient -- it finds the appropriate width of each column, and displays the text as a nicely formatted table.

注意:有空字段,则需要在其中放入某种类型的占位符,否则该列将与以下列合并。下面的示例演示如何使用 sed 插入占位符:

Note: whenever you have empty fields, you need to put some kind of placeholder in it, otherwise the column gets merged with following columns. The following example demonstrates how to use sed to insert a placeholder:

$ 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 ,因为第二个逗号是已匹配。

Note that the substitution of ,, for , , is done twice. If you do it only once, 1,,,4 will become 1, ,,4 since the second comma is matched already.

这篇关于命令行CSV查看器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆