table-pretty

command module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2022 License: MIT Imports: 6 Imported by: 0

README

table

table is a utility tool to print CSV or JSON documents in a table format.

Installation

Homebrew
brew install elwin/tols/table
Snap
snap install table
Go

Requires a go toolchain installation to be present.

go get github.com/elwin/table

Usage

$ echo 'id,name,price
  1,apple,15
  2,banana,10' | table
+----+--------+-------+
| ID |  NAME  | PRICE |
+----+--------+-------+
|  1 | apple  |    15 |
|  2 | banana |    10 |
+----+--------+-------+

By default, CSV will be assumed. Alternatively, JSON can be used by specifying --format json or -f json:

$ echo '[
  {
    "id": "1",
    "name": "apple",
    "price": "15"
  },
  {
    "id": "2",
    "name": "banana",
    "price": "10"
  }
]' | table --format json
+----+--------+-------+
| ID |  NAME  | PRICE |
+----+--------+-------+
|  1 | apple  |    15 |
|  2 | banana |    10 |
+----+--------+-------+

Instead of reading from stdin we can also specify a file using -i or --input-file:

$ table --input-file testfiles/sample.csv
+----+--------+-------+
| ID |  NAME  | PRICE |
+----+--------+-------+
|  1 | apple  |    15 |
|  2 | banana |    10 |
+----+--------+-------+

Limitations

Ordering in JSON results

When using a JSON document as input, the headers are sorted alphabetically. This is due to the usage of map[string]string when un-marshalling, which otherwise gives non-deterministic results.

JSON document format

The JSON documents needs to contain a list as the top-level structure and non-nested dictionaries as elements of this list.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL