This project is born from a desire to work with space-delineated tables in a programmatic way, for example the output of
kubectl
or a help message generated by envconfig
.
It parses fixed-width columnar text and can output in a variety of formats. When multiple rows of data are present, it
assumes the first row is the header row. This will become the keys of outputted objects when outputting in JSON or YAML.
json
yaml
csv
markdown
go install github.com/ryantate13/space-table@latest
$ space-table --help
Usage: space-table [options]...
Transforms space-aligned tabular data from stdin or a file to various formats.
Options:
-i, --input input file, defaults to stdin, pass - to set input to stdin explicitly
-o, --output output format, defaults to csv, allowed values are: csv, json, md, markdown, yml, yaml
-h, --help show this help message and quit
-v, --version show version and quit
Examples:
space-table < table.txt
space-table --input table.txt
space-table --output json < table.txt
space-table --output csv --input table.txt
kubectl get pods -o wide | space-table
my-command-that-outputs-tabular-data | space-table -o json > table.json
$ kubectl get pods | head -n 2 | space-table -o md
| NAME | READY | STATUS | RESTARTS | AGE |
|--------------------------------------|-------|---------|----------|-----|
| app-foo-bar-baz-pod-1234567890-asdfg | 1/1 | Running | 0 | 1d |
$ app-that-uses-envconfig --help | tail -n +3 | space-table -o json
[
{
"DEFAULT": "dev",
"DESCRIPTION": "application environment",
"KEY": "APP_ENV",
"REQUIRED": "true",
"TYPE": "String"
},
{
"DEFAULT": "1m",
"DESCRIPTION": "http request timeout",
"KEY": "APP_HTTP_REQUEST_TIMEOUT",
"REQUIRED": "",
"TYPE": "Duration"
},
...
]