View CSV files in the command line
- C++ 99.9%
- Makefile 0.1%
|
|
||
|---|---|---|
| examples | example files | |
| include | Add different styles ( fixes #1 ) | |
| src | Add different styles ( fixes #1 ) | |
| tests | Added framework for tests | |
| .gitignore | Added framework for tests | |
| csvcat.cpp | Add different styles ( fixes #1 ) | |
| Makefile | Added framework for tests | |
| README.md | README.md add example vertical view | |
csvcat
Format the contents of a CSV-file and write to standard out.
Example output (note that for some reason the column with the vertical hypens are not aligned properly when displayed in the broser. In all terminals tested the column to align properly):
$ ./csvcat examples/iris.csv
┌────────────┬───────────┬────────────┬───────────┬─────────┐
│Sepal.Length│Sepal.Width│Petal.Length│Petal.Width│ Species│
├────────────┼───────────┼────────────┼───────────┼─────────┤
│ 5.1│ 3.5│ 1.4│ 0.2│ setosa│
│ 4.9│ 3│ 1.4│ 0.2│ setosa│
│ 4.7│ 3.2│ 1.3│ 0.2│ setosa│
│ 4.6│ 3.1│ 1.5│ 0.2│ setosa│
│ 5│ 3.6│ 1.4│ 0.2│ setosa│
│ 5.4│ 3.9│ 1.7│ 0.4│ setosa│
│ 4.6│ 3.4│ 1.4│ 0.3│ setosa│
│ 5│ 3.4│ 1.5│ 0.2│ setosa│
│ 4.4│ 2.9│ 1.4│ 0.2│ setosa│
│ 4.9│ 3.1│ 1.5│ 0.1│ setosa│
│ 5.4│ 3.7│ 1.5│ 0.2│ setosa│
│ 4.8│ 3.4│ 1.6│ 0.2│ setosa│
│ 4.8│ 3│ 1.4│ 0.1│ setosa│
│ 4.3│ 3│ 1.1│ 0.1│ setosa│
│ 5.8│ 4│ 1.2│ 0.2│ setosa│
│ 5.7│ 4.4│ 1.5│ 0.4│ setosa│
│ 5.4│ 3.9│ 1.3│ 0.4│ setosa│
│ 5.1│ 3.5│ 1.4│ 0.3│ setosa│
│ 5.7│ 3.8│ 1.7│ 0.3│ setosa│
│ 5.1│ 3.8│ 1.5│ 0.3│ setosa│
│ ⋮│ ⋮│ ⋮│ ⋮│ ⋮│
│ 7.4│ 2.8│ 6.1│ 1.9│virginica│
│ 7.9│ 3.8│ 6.4│ 2│virginica│
│ 6.4│ 2.8│ 5.6│ 2.2│virginica│
│ 6.3│ 2.8│ 5.1│ 1.5│virginica│
│ 6.1│ 2.6│ 5.6│ 1.4│virginica│
│ 7.7│ 3│ 6.1│ 2.3│virginica│
│ 6.3│ 3.4│ 5.6│ 2.4│virginica│
│ 6.4│ 3.1│ 5.5│ 1.8│virginica│
│ 6│ 3│ 4.8│ 1.8│virginica│
│ 6.9│ 3.1│ 5.4│ 2.1│virginica│
│ 6.7│ 3.1│ 5.6│ 2.4│virginica│
│ 6.9│ 3.1│ 5.1│ 2.3│virginica│
│ 5.8│ 2.7│ 5.1│ 1.9│virginica│
│ 6.8│ 3.2│ 5.9│ 2.3│virginica│
│ 6.7│ 3.3│ 5.7│ 2.5│virginica│
│ 6.7│ 3│ 5.2│ 2.3│virginica│
│ 6.3│ 2.5│ 5│ 1.9│virginica│
│ 6.5│ 3│ 5.2│ 2│virginica│
│ 6.2│ 3.4│ 5.4│ 2.3│virginica│
│ 5.9│ 3│ 5.1│ 1.8│virginica│
└────────────┴───────────┴────────────┴───────────┴─────────┘
$ ./csvcat examples/iris.csv --ntail=0 --columns=Species,Sepal.Length-Sepal.Width
┌───────┬────────────┬───────────┐
│Species│Sepal.Length│Sepal.Width│
├───────┼────────────┼───────────┤
│ setosa│ 5.1│ 3.5│
│ setosa│ 4.9│ 3│
│ setosa│ 4.7│ 3.2│
│ setosa│ 4.6│ 3.1│
│ setosa│ 5│ 3.6│
│ setosa│ 5.4│ 3.9│
│ setosa│ 4.6│ 3.4│
│ setosa│ 5│ 3.4│
│ setosa│ 4.4│ 2.9│
│ setosa│ 4.9│ 3.1│
│ setosa│ 5.4│ 3.7│
│ setosa│ 4.8│ 3.4│
│ setosa│ 4.8│ 3│
│ setosa│ 4.3│ 3│
│ setosa│ 5.8│ 4│
│ setosa│ 5.7│ 4.4│
│ setosa│ 5.4│ 3.9│
│ setosa│ 5.1│ 3.5│
│ setosa│ 5.7│ 3.8│
│ setosa│ 5.1│ 3.8│
└───────┴────────────┴───────────┘
The vertical view can be practical for CSV files with a large number of columns as it will show all columns.
$ ./csvcat --vertical examples/employ.csv
id : 368509515, 273040044, 854856378, 429782078, 949458305, 921370403, 640668848, 58820512,
549758863, 902078272
dob : 1993年06月14日, 1982年06月17日, 1990年01月30日, 2019年09月23日, 2005年06月16日, 1981年09月14日, 1993年08月30日,
1962年10月13日, 1990年06月09日, 1962年05月29日
gender : M, F, F, M, F, F, M, M, M, F
employ : E, E, E, N, N, E, E, E, E, E
income : 269ドル.18, 533ドル.65, 716,79,ドル NA, NA, 1ドル 461,36, 708,98,ドル 2ドル 243,1, 719,69,ドル 618,27ドル
haspartner: N, N, Y, N, N, N, Y, N, Y, N
id2 : 187844355, 963831798, 20072760, 711292034, 911459071, 26901869, 996464509,
288242988, 998045846, 594477489
dob2 : 1961年10月08日, 1965年02月15日, 1961年08月18日, 1994年02月16日, 2007年02月27日, 1981年03月08日, 1960年12月10日,
2013年06月11日, 1973年01月25日, 1952年08月31日
gender2 : X, M, F, M, F, F, M, M, F, -
employ2 : U, E, E, E, N, E, E, N, E, N
income2 : NA, 790,13, 1 651,6, 455,98, NA, 1 153,02, 1 088,99, NA, 1 312,45, NA
haspartner: N, N, N, N, N, Y, N, N, N, Y
Building
Building should be relatively easy. The dependencies are:
- C++ compiler supporting C++20 (e.g. any recent version of
gccofclangshould work). - Development libraries of
libicu. On debian based distribution these can be installed usingapt install libicu-dev.
The tool can be built using the following commands:
git clone --depth=1 https://codeberg.org/djvanderlaan/csvcat.git
csv csvcat
make
Put the resulting binary csvcat wherever you keer your binaries.