Command line CSV viewer? [closed]

2019-01-12 12:59发布

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.

19条回答
干净又极端
2楼-- · 2019-01-12 13:34

My FOSS project CSVfix allows you to display CSV files in "ASCII art" table format.

查看更多
Melony?
3楼-- · 2019-01-12 13:34

Using TxtSushi you can do:

csvtopretty filename.csv | less -S
查看更多
▲ chillily
4楼-- · 2019-01-12 13:37

xsv is more than a viewer. I recommend it for most CSV task on the command line, especially when dealing with large datasets.

查看更多
女痞
5楼-- · 2019-01-12 13:39

I've created tablign for these (and other) purposes. Install with

[sudo -H] pip3 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 ,

Also works if the data is separated by something else than commas. Most importantly, it preserves the delimiters so you can also use it to style your ASCII tables without sacrificing your [Markdown,CSV,LaTeX] syntax.

查看更多
倾城 Initia
6楼-- · 2019-01-12 13:40

I used pisswillis's answer for a long time.

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

But then combined some code I found at http://chrisjean.com/2011/06/17/view-csv-data-from-the-command-line which works better for me:

csview()
{
    local file="$1"
    cat "$file" | sed -e 's/,,/, ,/g' | column -s, -t | less -#5 -N -S
}

The reason it works better for me is that it handles wide columns better.

查看更多
别忘想泡老子
7楼-- · 2019-01-12 13:43

I wrote a script, viewtab , in Groovy for just this purpose. You invoke it like:

viewtab filename.csv

It is basically a super-lightweight spreadsheet that can be invoked from the command line, handles CSV and tab separated files, can read VERY large files that Excel and Numbers choke on, and is very fast. It's not command-line in the sense of being text-only, but it is platform independent and will probably fit the bill for many people looking for a solution to the problem of quickly inspecting many or large CSV files while working in a command line environment.

The script and how to install it are described here:

http://bayesianconspiracy.blogspot.com/2012/06/quick-csvtab-file-viewer.html

查看更多
登录 后发表回答