mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-19 05:21:03 +01:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5be18e27c9 | |||
| 2c410e1cb3 | |||
| 1b622284a1 | |||
| 404481c3dc | |||
| 15f437314a | |||
| 3746c7f326 | |||
| b7b638636d | |||
| dd13300c8b | |||
| a59a6cb7d8 | |||
| d7ea0017b7 | |||
| 09dc1f3e60 | |||
| 43dc4ff031 | |||
| 4596d9d589 |
@@ -1,38 +0,0 @@
|
|||||||
---
|
|
||||||
version: 2.1
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
compile:
|
|
||||||
docker:
|
|
||||||
- image: cimg/go:1.18
|
|
||||||
steps:
|
|
||||||
- checkout
|
|
||||||
- run: make
|
|
||||||
|
|
||||||
test:
|
|
||||||
parameters:
|
|
||||||
go_version:
|
|
||||||
type: string
|
|
||||||
run_test:
|
|
||||||
type: boolean
|
|
||||||
default: true
|
|
||||||
docker:
|
|
||||||
- image: cimg/go:<< parameters.go_version >>
|
|
||||||
steps:
|
|
||||||
- checkout
|
|
||||||
- run: make test
|
|
||||||
|
|
||||||
workflows:
|
|
||||||
version: 2
|
|
||||||
unit-test:
|
|
||||||
jobs:
|
|
||||||
- compile
|
|
||||||
- test:
|
|
||||||
name: testing
|
|
||||||
matrix:
|
|
||||||
parameters:
|
|
||||||
go_version:
|
|
||||||
- "1.16"
|
|
||||||
- "1.17"
|
|
||||||
- "1.18"
|
|
||||||
- "1.19"
|
|
||||||
25
.github/workflows/ci.yaml
vendored
Normal file
25
.github/workflows/ci.yaml
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
name: build-and-test-tablizer
|
||||||
|
on: [push, pull_request]
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
version: [1.17, 1.18, 1.19]
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
name: Build
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- name: Set up Go 1.18
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.version }}
|
||||||
|
id: go
|
||||||
|
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: build
|
||||||
|
run: make
|
||||||
|
|
||||||
|
- name: test
|
||||||
|
run: make test
|
||||||
25
Makefile
25
Makefile
@@ -18,19 +18,30 @@
|
|||||||
#
|
#
|
||||||
# no need to modify anything below
|
# no need to modify anything below
|
||||||
tool = tablizer
|
tool = tablizer
|
||||||
version = $(shell egrep "^var Version = " lib/common.go | cut -d'=' -f2 | cut -d'"' -f 2)
|
version = $(shell egrep "= .v" lib/common.go | cut -d'=' -f2 | cut -d'"' -f 2)
|
||||||
archs = android darwin freebsd linux netbsd openbsd windows
|
archs = android darwin freebsd linux netbsd openbsd windows
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
UID = root
|
UID = root
|
||||||
GID = 0
|
GID = 0
|
||||||
|
BRANCH = $(shell git describe --all | cut -d/ -f2)
|
||||||
|
COMMIT = $(shell git rev-parse --short=8 HEAD)
|
||||||
|
BUILD = $(shell date +%Y.%m.%d.%H%M%S)
|
||||||
|
VERSION:= $(if $(filter $(BRANCH), development),$(version)-$(BRANCH)-$(COMMIT)-$(BUILD))
|
||||||
|
|
||||||
all: buildlocal $(tool).1
|
|
||||||
|
all: $(tool).1 cmd/$(tool).go buildlocal
|
||||||
|
|
||||||
%.1: %.pod
|
%.1: %.pod
|
||||||
pod2man -c "User Commands" -r 1 -s 1 $*.pod > $*.1
|
pod2man -c "User Commands" -r 1 -s 1 $*.pod > $*.1
|
||||||
|
|
||||||
|
cmd/%.go: %.pod
|
||||||
|
echo "package cmd" > cmd/$*.go
|
||||||
|
echo "var manpage = \`" >> cmd/$*.go
|
||||||
|
pod2text $*.pod >> cmd/$*.go
|
||||||
|
echo "\`" >> cmd/$*.go
|
||||||
|
|
||||||
buildlocal:
|
buildlocal:
|
||||||
go build
|
go build -ldflags "-X 'github.com/tlinden/tablizer/lib.VERSION=$(VERSION)'"
|
||||||
|
|
||||||
release:
|
release:
|
||||||
./mkrel.sh $(tool) $(version)
|
./mkrel.sh $(tool) $(version)
|
||||||
@@ -42,7 +53,7 @@ install: buildlocal
|
|||||||
install -o $(UID) -g $(GID) -m 444 $(tool).1 $(PREFIX)/man/man1/
|
install -o $(UID) -g $(GID) -m 444 $(tool).1 $(PREFIX)/man/man1/
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(tool) $(tool).1 releases
|
rm -rf $(tool) releases
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test -v ./...
|
go test -v ./...
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
[](https://app.circleci.com/pipelines/github/TLINDEN/tablizer)
|
[](https://github.com/tlinden/tablizer/actions)
|
||||||
|
[](https://github.com/tlinden/tablizer/blob/master/LICENSE)
|
||||||
|
|
||||||
## tablizer - Manipulate tabular output of other programs
|
## tablizer - Manipulate tabular output of other programs
|
||||||
|
|
||||||
|
|||||||
35
cmd/root.go
35
cmd/root.go
@@ -17,19 +17,46 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"daemon.de/tablizer/lib"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/tlinden/tablizer/lib"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ShowManual = false
|
||||||
|
|
||||||
|
func man() {
|
||||||
|
man := exec.Command("less", "-")
|
||||||
|
|
||||||
|
var b bytes.Buffer
|
||||||
|
b.Write([]byte(manpage))
|
||||||
|
|
||||||
|
man.Stdout = os.Stdout
|
||||||
|
man.Stdin = &b
|
||||||
|
man.Stderr = os.Stderr
|
||||||
|
|
||||||
|
err := man.Run()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "tablizer [regex] [file, ...]",
|
Use: "tablizer [regex] [file, ...]",
|
||||||
Short: "[Re-]tabularize tabular data",
|
Short: "[Re-]tabularize tabular data",
|
||||||
Long: `Manipulate tabular output of other programs`,
|
Long: `Manipulate tabular output of other programs`,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if lib.ShowVersion {
|
if lib.ShowVersion {
|
||||||
fmt.Printf("This is tablizer version %s\n", lib.Version)
|
fmt.Printf("This is tablizer version %s\n", lib.VERSION)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if ShowManual {
|
||||||
|
man()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +84,9 @@ func Execute() {
|
|||||||
func init() {
|
func init() {
|
||||||
rootCmd.PersistentFlags().BoolVarP(&lib.Debug, "debug", "d", false, "Enable debugging")
|
rootCmd.PersistentFlags().BoolVarP(&lib.Debug, "debug", "d", false, "Enable debugging")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&lib.NoNumbering, "no-numbering", "n", false, "Disable header numbering")
|
rootCmd.PersistentFlags().BoolVarP(&lib.NoNumbering, "no-numbering", "n", false, "Disable header numbering")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&lib.ShowVersion, "version", "v", false, "Print program version")
|
rootCmd.PersistentFlags().BoolVarP(&lib.ShowVersion, "version", "V", false, "Print program version")
|
||||||
|
rootCmd.PersistentFlags().BoolVarP(&lib.InvertMatch, "invert-match", "v", false, "select non-matching rows")
|
||||||
|
rootCmd.PersistentFlags().BoolVarP(&ShowManual, "man", "m", false, "Display manual page")
|
||||||
rootCmd.PersistentFlags().StringVarP(&lib.Separator, "separator", "s", "", "Custom field separator")
|
rootCmd.PersistentFlags().StringVarP(&lib.Separator, "separator", "s", "", "Custom field separator")
|
||||||
rootCmd.PersistentFlags().StringVarP(&lib.Columns, "columns", "c", "", "Only show the speficied columns (separated by ,)")
|
rootCmd.PersistentFlags().StringVarP(&lib.Columns, "columns", "c", "", "Only show the speficied columns (separated by ,)")
|
||||||
|
|
||||||
|
|||||||
131
cmd/tablizer.go
Normal file
131
cmd/tablizer.go
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
package cmd
|
||||||
|
var manpage = `
|
||||||
|
NAME
|
||||||
|
tablizer - Manipulate tabular output of other programs
|
||||||
|
|
||||||
|
SYNOPSIS
|
||||||
|
Usage:
|
||||||
|
tablizer [regex] [file, ...] [flags]
|
||||||
|
|
||||||
|
Flags:
|
||||||
|
-c, --columns string Only show the speficied columns (separated by ,)
|
||||||
|
-d, --debug Enable debugging
|
||||||
|
-h, --help help for tablizer
|
||||||
|
-v, --invert-match select non-matching rows
|
||||||
|
-m, --man Display manual page
|
||||||
|
-n, --no-numbering Disable header numbering
|
||||||
|
-o, --output string Output mode - one of: orgtbl, markdown, extended, ascii(default)
|
||||||
|
-X, --extended Enable extended output
|
||||||
|
-M, --markdown Enable markdown table output
|
||||||
|
-O, --orgtbl Enable org-mode table output
|
||||||
|
-s, --separator string Custom field separator
|
||||||
|
-v, --version Print program version
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
Many programs generate tabular output. But sometimes you need to
|
||||||
|
post-process these tables, you may need to remove one or more columns or
|
||||||
|
you may want to filter for some pattern or you may need the output in
|
||||||
|
another program and need to parse it somehow. Standard unix tools such
|
||||||
|
as awk(1), grep(1) or column(1) may help, but sometimes it's a tedious
|
||||||
|
business.
|
||||||
|
|
||||||
|
Let's take the output of the tool kubectl. It contains cells with
|
||||||
|
withespace and they do not separate columns by TAB characters. This is
|
||||||
|
not easy to process.
|
||||||
|
|
||||||
|
You can use tablizer to do these and more things.
|
||||||
|
|
||||||
|
tablizer analyses the header fiels of a table, registers the column
|
||||||
|
positions of each header field and separates columns by those positions.
|
||||||
|
|
||||||
|
Without any options it reads its input from "STDIN", but you can also
|
||||||
|
specify a file as a parameter. If you want to reduce the output by some
|
||||||
|
regular expression, just specify it as its first parameter. You may also
|
||||||
|
use the -v option to exclude all rows which match the pattern. Hence:
|
||||||
|
|
||||||
|
# read from STDIN
|
||||||
|
kubectl get pods | tablizer
|
||||||
|
|
||||||
|
# read a file
|
||||||
|
tablizer filename
|
||||||
|
|
||||||
|
# search for pattern in a file (works like grep)
|
||||||
|
tablizer regex filename
|
||||||
|
|
||||||
|
# search for pattern in STDIN
|
||||||
|
kubectl get pods | tablizer regex
|
||||||
|
|
||||||
|
The output looks like the original one but every header field will have
|
||||||
|
a numer associated with it, e.g.:
|
||||||
|
|
||||||
|
NAME(1) READY(2) STATUS(3) RESTARTS(4) AGE(5)
|
||||||
|
|
||||||
|
These numbers denote the column and you can use them to specify which
|
||||||
|
columns you want to have in your output:
|
||||||
|
|
||||||
|
kubectl get pods | tablizer -c1,3
|
||||||
|
|
||||||
|
You can specify the numbers in any order but output will always follow
|
||||||
|
the original order.
|
||||||
|
|
||||||
|
The numbering can be suppressed by using the -n option.
|
||||||
|
|
||||||
|
Finally the -d option enables debugging output which is mostly usefull
|
||||||
|
for the developer.
|
||||||
|
|
||||||
|
OUTPUT MODES
|
||||||
|
There might be cases when the tabular output of a program is way too
|
||||||
|
large for your current terminal but you still need to see every column.
|
||||||
|
In such cases the -o extended or -X option can be usefull which enables
|
||||||
|
*extended mode*. In this mode, each row will be printed vertically,
|
||||||
|
header left, value right, aligned by the field widths. Here's an
|
||||||
|
example:
|
||||||
|
|
||||||
|
kubectl get pods | ./tablizer -o extended
|
||||||
|
NAME: repldepl-7bcd8d5b64-7zq4l
|
||||||
|
READY: 1/1
|
||||||
|
STATUS: Running
|
||||||
|
RESTARTS: 1 (71m ago)
|
||||||
|
AGE: 5h28m
|
||||||
|
|
||||||
|
You can of course still use a regex to reduce the number of rows
|
||||||
|
displayed.
|
||||||
|
|
||||||
|
The option -o shell can be used if the output has to be processed by the
|
||||||
|
shell, it prints variable assignments for each cell, one line per row:
|
||||||
|
|
||||||
|
kubectl get pods | ./tablizer -o extended ./tablizer -o shell
|
||||||
|
NAME="repldepl-7bcd8d5b64-7zq4l" READY="1/1" STATUS="Running" RESTARTS="9 (47m ago)" AGE="4d23h"
|
||||||
|
NAME="repldepl-7bcd8d5b64-m48n8" READY="1/1" STATUS="Running" RESTARTS="9 (47m ago)" AGE="4d23h"
|
||||||
|
NAME="repldepl-7bcd8d5b64-q2bf4" READY="1/1" STATUS="Running" RESTARTS="9 (47m ago)" AGE="4d23h"
|
||||||
|
|
||||||
|
You can use this in an eval loop.
|
||||||
|
|
||||||
|
Beside normal ascii mode (the default) and extended mode there are more
|
||||||
|
output modes available: orgtbl which prints an Emacs org-mode table and
|
||||||
|
markdown which prints a Markdown table.
|
||||||
|
|
||||||
|
BUGS
|
||||||
|
In order to report a bug, unexpected behavior, feature requests or to
|
||||||
|
submit a patch, please open an issue on github:
|
||||||
|
<https://github.com/TLINDEN/tablizer/issues>.
|
||||||
|
|
||||||
|
LICENSE
|
||||||
|
This software is licensed under the GNU GENERAL PUBLIC LICENSE version
|
||||||
|
3.
|
||||||
|
|
||||||
|
Copyright (c) 2022 by Thomas von Dein
|
||||||
|
|
||||||
|
This software uses the following GO libraries:
|
||||||
|
|
||||||
|
repr (https://github.com/alecthomas/repr)
|
||||||
|
Released under the MIT License, Copyright (c) 2016 Alec Thomas
|
||||||
|
|
||||||
|
cobra (https://github.com/spf13/cobra)
|
||||||
|
Released under the Apache 2.0 license, Copyright 2013-2022 The Cobra
|
||||||
|
Authors
|
||||||
|
|
||||||
|
AUTHORS
|
||||||
|
Thomas von Dein tom AT vondein DOT org
|
||||||
|
|
||||||
|
`
|
||||||
2
go.mod
2
go.mod
@@ -1,4 +1,4 @@
|
|||||||
module daemon.de/tablizer
|
module github.com/tlinden/tablizer
|
||||||
|
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
|
|||||||
@@ -17,19 +17,30 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
package lib
|
package lib
|
||||||
|
|
||||||
// command line flags
|
var (
|
||||||
var Debug bool
|
// command line flags
|
||||||
var XtendedOut bool
|
Debug bool
|
||||||
var NoNumbering bool
|
XtendedOut bool
|
||||||
var ShowVersion bool
|
NoNumbering bool
|
||||||
var Columns string
|
ShowVersion bool
|
||||||
var UseColumns []int
|
Columns string
|
||||||
var Separator string
|
UseColumns []int
|
||||||
var OutflagExtended bool
|
Separator string
|
||||||
var OutflagMarkdown bool
|
OutflagExtended bool
|
||||||
var OutflagOrgtable bool
|
OutflagMarkdown bool
|
||||||
var OutflagShell bool
|
OutflagOrgtable bool
|
||||||
var OutputMode string
|
OutflagShell bool
|
||||||
|
OutputMode string
|
||||||
|
InvertMatch bool
|
||||||
|
|
||||||
var Version = "v1.0.3"
|
// used for validation
|
||||||
var validOutputmodes = "(orgtbl|markdown|extended|ascii)"
|
validOutputmodes = "(orgtbl|markdown|extended|ascii)"
|
||||||
|
|
||||||
|
// main program version
|
||||||
|
Version = "v1.0.5"
|
||||||
|
|
||||||
|
// generated version string, used by -v contains lib.Version on
|
||||||
|
// main branch, and lib.Version-$branch-$lastcommit-$date on
|
||||||
|
// development branch
|
||||||
|
VERSION string
|
||||||
|
)
|
||||||
|
|||||||
@@ -114,7 +114,11 @@ func parseFile(input io.Reader, pattern string) (Tabdata, error) {
|
|||||||
} else {
|
} else {
|
||||||
// data processing
|
// data processing
|
||||||
if len(pattern) > 0 {
|
if len(pattern) > 0 {
|
||||||
if !patternR.MatchString(line) {
|
if patternR.MatchString(line) == InvertMatch {
|
||||||
|
// by default -v is false, so if a line does NOT
|
||||||
|
// match the pattern, we will ignore it. However,
|
||||||
|
// if the user specified -v, the matching is inverted,
|
||||||
|
// so we ignore all lines, which DO match.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -151,7 +155,7 @@ func parseFile(input io.Reader, pattern string) (Tabdata, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if scanner.Err() != nil {
|
if scanner.Err() != nil {
|
||||||
return data, errors.Unwrap(fmt.Errorf("Regexp pattern %s is invalid: %w", pattern, scanner.Err()))
|
return data, errors.Unwrap(fmt.Errorf("Failed to read from io.Reader: %w", scanner.Err()))
|
||||||
}
|
}
|
||||||
|
|
||||||
if Debug {
|
if Debug {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
package lib
|
package lib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -80,3 +81,57 @@ asd igig cxxxncnc
|
|||||||
t.Errorf("Parser returned invalid data\nExp: %+v\nGot: %+v\n", data, gotdata)
|
t.Errorf("Parser returned invalid data\nExp: %+v\nGot: %+v\n", data, gotdata)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParserPatternmatching(t *testing.T) {
|
||||||
|
var tests = []struct {
|
||||||
|
entries [][]string
|
||||||
|
pattern string
|
||||||
|
invert bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
entries: [][]string{
|
||||||
|
[]string{
|
||||||
|
"asd",
|
||||||
|
"igig",
|
||||||
|
"cxxxncnc",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pattern: "ig",
|
||||||
|
invert: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
entries: [][]string{
|
||||||
|
[]string{
|
||||||
|
"19191",
|
||||||
|
"EDD 1",
|
||||||
|
"X",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pattern: "ig",
|
||||||
|
invert: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
table := `ONE TWO THREE
|
||||||
|
asd igig cxxxncnc
|
||||||
|
19191 EDD 1 X`
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
testname := fmt.Sprintf("parse-with-inverted-pattern-%t", tt.invert)
|
||||||
|
t.Run(testname, func(t *testing.T) {
|
||||||
|
InvertMatch = tt.invert
|
||||||
|
|
||||||
|
readFd := strings.NewReader(table)
|
||||||
|
gotdata, err := parseFile(readFd, tt.pattern)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Parser returned error: %s\nData processed so far: %+v", err, gotdata)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(tt.entries, gotdata.entries) {
|
||||||
|
t.Errorf("Parser returned invalid data (pattern: %s, invert: %t)\nExp: %+v\nGot: %+v\n",
|
||||||
|
tt.pattern, tt.invert, tt.entries, gotdata.entries)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"daemon.de/tablizer/cmd"
|
"github.com/tlinden/tablizer/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
280
tablizer.1
Normal file
280
tablizer.1
Normal file
@@ -0,0 +1,280 @@
|
|||||||
|
.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
|
||||||
|
.\"
|
||||||
|
.\" Standard preamble:
|
||||||
|
.\" ========================================================================
|
||||||
|
.de Sp \" Vertical space (when we can't use .PP)
|
||||||
|
.if t .sp .5v
|
||||||
|
.if n .sp
|
||||||
|
..
|
||||||
|
.de Vb \" Begin verbatim text
|
||||||
|
.ft CW
|
||||||
|
.nf
|
||||||
|
.ne \\$1
|
||||||
|
..
|
||||||
|
.de Ve \" End verbatim text
|
||||||
|
.ft R
|
||||||
|
.fi
|
||||||
|
..
|
||||||
|
.\" Set up some character translations and predefined strings. \*(-- will
|
||||||
|
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
|
||||||
|
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
|
||||||
|
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
|
||||||
|
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
|
||||||
|
.\" nothing in troff, for use with C<>.
|
||||||
|
.tr \(*W-
|
||||||
|
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
|
||||||
|
.ie n \{\
|
||||||
|
. ds -- \(*W-
|
||||||
|
. ds PI pi
|
||||||
|
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
|
||||||
|
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
|
||||||
|
. ds L" ""
|
||||||
|
. ds R" ""
|
||||||
|
. ds C` ""
|
||||||
|
. ds C' ""
|
||||||
|
'br\}
|
||||||
|
.el\{\
|
||||||
|
. ds -- \|\(em\|
|
||||||
|
. ds PI \(*p
|
||||||
|
. ds L" ``
|
||||||
|
. ds R" ''
|
||||||
|
. ds C`
|
||||||
|
. ds C'
|
||||||
|
'br\}
|
||||||
|
.\"
|
||||||
|
.\" Escape single quotes in literal strings from groff's Unicode transform.
|
||||||
|
.ie \n(.g .ds Aq \(aq
|
||||||
|
.el .ds Aq '
|
||||||
|
.\"
|
||||||
|
.\" If the F register is >0, we'll generate index entries on stderr for
|
||||||
|
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
|
||||||
|
.\" entries marked with X<> in POD. Of course, you'll have to process the
|
||||||
|
.\" output yourself in some meaningful fashion.
|
||||||
|
.\"
|
||||||
|
.\" Avoid warning from groff about undefined register 'F'.
|
||||||
|
.de IX
|
||||||
|
..
|
||||||
|
.nr rF 0
|
||||||
|
.if \n(.g .if rF .nr rF 1
|
||||||
|
.if (\n(rF:(\n(.g==0)) \{\
|
||||||
|
. if \nF \{\
|
||||||
|
. de IX
|
||||||
|
. tm Index:\\$1\t\\n%\t"\\$2"
|
||||||
|
..
|
||||||
|
. if !\nF==2 \{\
|
||||||
|
. nr % 0
|
||||||
|
. nr F 2
|
||||||
|
. \}
|
||||||
|
. \}
|
||||||
|
.\}
|
||||||
|
.rr rF
|
||||||
|
.\"
|
||||||
|
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
|
||||||
|
.\" Fear. Run. Save yourself. No user-serviceable parts.
|
||||||
|
. \" fudge factors for nroff and troff
|
||||||
|
.if n \{\
|
||||||
|
. ds #H 0
|
||||||
|
. ds #V .8m
|
||||||
|
. ds #F .3m
|
||||||
|
. ds #[ \f1
|
||||||
|
. ds #] \fP
|
||||||
|
.\}
|
||||||
|
.if t \{\
|
||||||
|
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
|
||||||
|
. ds #V .6m
|
||||||
|
. ds #F 0
|
||||||
|
. ds #[ \&
|
||||||
|
. ds #] \&
|
||||||
|
.\}
|
||||||
|
. \" simple accents for nroff and troff
|
||||||
|
.if n \{\
|
||||||
|
. ds ' \&
|
||||||
|
. ds ` \&
|
||||||
|
. ds ^ \&
|
||||||
|
. ds , \&
|
||||||
|
. ds ~ ~
|
||||||
|
. ds /
|
||||||
|
.\}
|
||||||
|
.if t \{\
|
||||||
|
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
|
||||||
|
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
|
||||||
|
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
|
||||||
|
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
|
||||||
|
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
|
||||||
|
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
|
||||||
|
.\}
|
||||||
|
. \" troff and (daisy-wheel) nroff accents
|
||||||
|
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
|
||||||
|
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
|
||||||
|
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
|
||||||
|
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
|
||||||
|
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
|
||||||
|
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
|
||||||
|
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
|
||||||
|
.ds ae a\h'-(\w'a'u*4/10)'e
|
||||||
|
.ds Ae A\h'-(\w'A'u*4/10)'E
|
||||||
|
. \" corrections for vroff
|
||||||
|
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
|
||||||
|
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
|
||||||
|
. \" for low resolution devices (crt and lpr)
|
||||||
|
.if \n(.H>23 .if \n(.V>19 \
|
||||||
|
\{\
|
||||||
|
. ds : e
|
||||||
|
. ds 8 ss
|
||||||
|
. ds o a
|
||||||
|
. ds d- d\h'-1'\(ga
|
||||||
|
. ds D- D\h'-1'\(hy
|
||||||
|
. ds th \o'bp'
|
||||||
|
. ds Th \o'LP'
|
||||||
|
. ds ae ae
|
||||||
|
. ds Ae AE
|
||||||
|
.\}
|
||||||
|
.rm #[ #] #H #V #F C
|
||||||
|
.\" ========================================================================
|
||||||
|
.\"
|
||||||
|
.IX Title "TABLIZER 1"
|
||||||
|
.TH TABLIZER 1 "2022-10-05" "1" "User Commands"
|
||||||
|
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||||
|
.\" way too many mistakes in technical documents.
|
||||||
|
.if n .ad l
|
||||||
|
.nh
|
||||||
|
.SH "NAME"
|
||||||
|
tablizer \- Manipulate tabular output of other programs
|
||||||
|
.SH "SYNOPSIS"
|
||||||
|
.IX Header "SYNOPSIS"
|
||||||
|
.Vb 2
|
||||||
|
\& Usage:
|
||||||
|
\& tablizer [regex] [file, ...] [flags]
|
||||||
|
\&
|
||||||
|
\& Flags:
|
||||||
|
\& \-c, \-\-columns string Only show the speficied columns (separated by ,)
|
||||||
|
\& \-d, \-\-debug Enable debugging
|
||||||
|
\& \-h, \-\-help help for tablizer
|
||||||
|
\& \-v, \-\-invert\-match select non\-matching rows
|
||||||
|
\& \-m, \-\-man Display manual page
|
||||||
|
\& \-n, \-\-no\-numbering Disable header numbering
|
||||||
|
\& \-o, \-\-output string Output mode \- one of: orgtbl, markdown, extended, ascii(default)
|
||||||
|
\& \-X, \-\-extended Enable extended output
|
||||||
|
\& \-M, \-\-markdown Enable markdown table output
|
||||||
|
\& \-O, \-\-orgtbl Enable org\-mode table output
|
||||||
|
\& \-s, \-\-separator string Custom field separator
|
||||||
|
\& \-v, \-\-version Print program version
|
||||||
|
.Ve
|
||||||
|
.SH "DESCRIPTION"
|
||||||
|
.IX Header "DESCRIPTION"
|
||||||
|
Many programs generate tabular output. But sometimes you need to
|
||||||
|
post-process these tables, you may need to remove one or more columns
|
||||||
|
or you may want to filter for some pattern or you may need the output
|
||||||
|
in another program and need to parse it somehow. Standard unix tools
|
||||||
|
such as \fBawk\fR\|(1), \fBgrep\fR\|(1) or \fBcolumn\fR\|(1) may help, but sometimes it's a
|
||||||
|
tedious business.
|
||||||
|
.PP
|
||||||
|
Let's take the output of the tool kubectl. It contains cells with
|
||||||
|
withespace and they do not separate columns by \s-1TAB\s0 characters. This is
|
||||||
|
not easy to process.
|
||||||
|
.PP
|
||||||
|
You can use \fBtablizer\fR to do these and more things.
|
||||||
|
.PP
|
||||||
|
\&\fBtablizer\fR analyses the header fiels of a table, registers the column
|
||||||
|
positions of each header field and separates columns by those
|
||||||
|
positions.
|
||||||
|
.PP
|
||||||
|
Without any options it reads its input from \f(CW\*(C`STDIN\*(C'\fR, but you can also
|
||||||
|
specify a file as a parameter. If you want to reduce the output by
|
||||||
|
some regular expression, just specify it as its first parameter. You
|
||||||
|
may also use the \fB\-v\fR option to exclude all rows which match the
|
||||||
|
pattern. Hence:
|
||||||
|
.PP
|
||||||
|
.Vb 2
|
||||||
|
\& # read from STDIN
|
||||||
|
\& kubectl get pods | tablizer
|
||||||
|
\&
|
||||||
|
\& # read a file
|
||||||
|
\& tablizer filename
|
||||||
|
\&
|
||||||
|
\& # search for pattern in a file (works like grep)
|
||||||
|
\& tablizer regex filename
|
||||||
|
\&
|
||||||
|
\& # search for pattern in STDIN
|
||||||
|
\& kubectl get pods | tablizer regex
|
||||||
|
.Ve
|
||||||
|
.PP
|
||||||
|
The output looks like the original one but every header field will
|
||||||
|
have a numer associated with it, e.g.:
|
||||||
|
.PP
|
||||||
|
.Vb 1
|
||||||
|
\& NAME(1) READY(2) STATUS(3) RESTARTS(4) AGE(5)
|
||||||
|
.Ve
|
||||||
|
.PP
|
||||||
|
These numbers denote the column and you can use them to specify which
|
||||||
|
columns you want to have in your output:
|
||||||
|
.PP
|
||||||
|
.Vb 1
|
||||||
|
\& kubectl get pods | tablizer \-c1,3
|
||||||
|
.Ve
|
||||||
|
.PP
|
||||||
|
You can specify the numbers in any order but output will always follow
|
||||||
|
the original order.
|
||||||
|
.PP
|
||||||
|
The numbering can be suppressed by using the \fB\-n\fR option.
|
||||||
|
.PP
|
||||||
|
Finally the \fB\-d\fR option enables debugging output which is mostly
|
||||||
|
usefull for the developer.
|
||||||
|
.SS "\s-1OUTPUT MODES\s0"
|
||||||
|
.IX Subsection "OUTPUT MODES"
|
||||||
|
There might be cases when the tabular output of a program is way too
|
||||||
|
large for your current terminal but you still need to see every
|
||||||
|
column. In such cases the \fB\-o extended\fR or \fB\-X\fR option can be
|
||||||
|
usefull which enables \fIextended mode\fR. In this mode, each row will be
|
||||||
|
printed vertically, header left, value right, aligned by the field
|
||||||
|
widths. Here's an example:
|
||||||
|
.PP
|
||||||
|
.Vb 6
|
||||||
|
\& kubectl get pods | ./tablizer \-o extended
|
||||||
|
\& NAME: repldepl\-7bcd8d5b64\-7zq4l
|
||||||
|
\& READY: 1/1
|
||||||
|
\& STATUS: Running
|
||||||
|
\& RESTARTS: 1 (71m ago)
|
||||||
|
\& AGE: 5h28m
|
||||||
|
.Ve
|
||||||
|
.PP
|
||||||
|
You can of course still use a regex to reduce the number of rows
|
||||||
|
displayed.
|
||||||
|
.PP
|
||||||
|
The option \fB\-o shell\fR can be used if the output has to be processed
|
||||||
|
by the shell, it prints variable assignments for each cell, one line
|
||||||
|
per row:
|
||||||
|
.PP
|
||||||
|
.Vb 4
|
||||||
|
\& kubectl get pods | ./tablizer \-o extended ./tablizer \-o shell
|
||||||
|
\& NAME="repldepl\-7bcd8d5b64\-7zq4l" READY="1/1" STATUS="Running" RESTARTS="9 (47m ago)" AGE="4d23h"
|
||||||
|
\& NAME="repldepl\-7bcd8d5b64\-m48n8" READY="1/1" STATUS="Running" RESTARTS="9 (47m ago)" AGE="4d23h"
|
||||||
|
\& NAME="repldepl\-7bcd8d5b64\-q2bf4" READY="1/1" STATUS="Running" RESTARTS="9 (47m ago)" AGE="4d23h"
|
||||||
|
.Ve
|
||||||
|
.PP
|
||||||
|
You can use this in an eval loop.
|
||||||
|
.PP
|
||||||
|
Beside normal ascii mode (the default) and extended mode there are
|
||||||
|
more output modes available: \fBorgtbl\fR which prints an Emacs org-mode
|
||||||
|
table and \fBmarkdown\fR which prints a Markdown table.
|
||||||
|
.SH "BUGS"
|
||||||
|
.IX Header "BUGS"
|
||||||
|
In order to report a bug, unexpected behavior, feature requests
|
||||||
|
or to submit a patch, please open an issue on github:
|
||||||
|
<https://github.com/TLINDEN/tablizer/issues>.
|
||||||
|
.SH "LICENSE"
|
||||||
|
.IX Header "LICENSE"
|
||||||
|
This software is licensed under the \s-1GNU GENERAL PUBLIC LICENSE\s0 version 3.
|
||||||
|
.PP
|
||||||
|
Copyright (c) 2022 by Thomas von Dein
|
||||||
|
.PP
|
||||||
|
This software uses the following \s-1GO\s0 libraries:
|
||||||
|
.IP "repr (https://github.com/alecthomas/repr)" 4
|
||||||
|
.IX Item "repr (https://github.com/alecthomas/repr)"
|
||||||
|
Released under the \s-1MIT\s0 License, Copyright (c) 2016 Alec Thomas
|
||||||
|
.IP "cobra (https://github.com/spf13/cobra)" 4
|
||||||
|
.IX Item "cobra (https://github.com/spf13/cobra)"
|
||||||
|
Released under the Apache 2.0 license, Copyright 2013\-2022 The Cobra Authors
|
||||||
|
.SH "AUTHORS"
|
||||||
|
.IX Header "AUTHORS"
|
||||||
|
Thomas von Dein \fBtom \s-1AT\s0 vondein \s-1DOT\s0 org\fR
|
||||||
@@ -11,6 +11,8 @@ tablizer - Manipulate tabular output of other programs
|
|||||||
-c, --columns string Only show the speficied columns (separated by ,)
|
-c, --columns string Only show the speficied columns (separated by ,)
|
||||||
-d, --debug Enable debugging
|
-d, --debug Enable debugging
|
||||||
-h, --help help for tablizer
|
-h, --help help for tablizer
|
||||||
|
-v, --invert-match select non-matching rows
|
||||||
|
-m, --man Display manual page
|
||||||
-n, --no-numbering Disable header numbering
|
-n, --no-numbering Disable header numbering
|
||||||
-o, --output string Output mode - one of: orgtbl, markdown, extended, ascii(default)
|
-o, --output string Output mode - one of: orgtbl, markdown, extended, ascii(default)
|
||||||
-X, --extended Enable extended output
|
-X, --extended Enable extended output
|
||||||
@@ -41,8 +43,9 @@ positions.
|
|||||||
|
|
||||||
Without any options it reads its input from C<STDIN>, but you can also
|
Without any options it reads its input from C<STDIN>, but you can also
|
||||||
specify a file as a parameter. If you want to reduce the output by
|
specify a file as a parameter. If you want to reduce the output by
|
||||||
some regular expression, just specify it as its first
|
some regular expression, just specify it as its first parameter. You
|
||||||
parameters. Hence:
|
may also use the B<-v> option to exclude all rows which match the
|
||||||
|
pattern. Hence:
|
||||||
|
|
||||||
# read from STDIN
|
# read from STDIN
|
||||||
kubectl get pods | tablizer
|
kubectl get pods | tablizer
|
||||||
|
|||||||
Reference in New Issue
Block a user