mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-18 13:01:11 +01:00
Compare commits
251 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 041feccb0b | |||
|
|
bd5ee90324 | ||
| bc717baa3f | |||
| c34f030914 | |||
|
|
f1aa9d0000 | ||
| 736dd37f16 | |||
| e0dc6bb845 | |||
|
|
8bdb3db105 | ||
| 4ce6c30f54 | |||
|
|
ec0b210167 | ||
| 253ef8262e | |||
| da48994744 | |||
| 39f06fddc8 | |||
|
|
50a9378d92 | ||
|
|
35b726fee4 | ||
|
|
8c87da34f2 | ||
|
|
6f0f5afb27 | ||
|
|
62b606e7da | ||
|
|
567d23b175 | ||
|
|
14f24533f0 | ||
|
|
4e413c02b5 | ||
|
|
6d8c0c0936 | ||
|
|
21b607af7c | ||
|
|
06a5d74fb6 | ||
|
|
5f3f7c417c | ||
|
|
687f4b7bb2 | ||
| 24b66b8a6b | |||
| d87c6878a4 | |||
| 4cdc4c8e18 | |||
| 9cb9a66332 | |||
| 24277cd716 | |||
| e51b141032 | |||
| 7af7304529 | |||
| b4c833a0ba | |||
| 1c36d93d65 | |||
|
|
ec864f42d6 | ||
|
|
4eaa676510 | ||
|
|
c600fb1136 | ||
|
|
abf9fac5c7 | ||
|
|
80dd6849ae | ||
| e2b82515f5 | |||
|
|
1976b4046e | ||
|
|
b1a2b3059e | ||
|
|
e3d6ef130c | ||
|
|
92fffaae9a | ||
|
|
f1c5ee5797 | ||
|
|
5168b04339 | ||
|
|
787178b17e | ||
|
|
eae39bbff1 | ||
| 40fbf17779 | |||
| 832841c1ff | |||
| 5726ed3f7f | |||
|
|
5e52cd9ce0 | ||
|
|
8c7c89c9ea | ||
| 25aa172c41 | |||
|
|
c436a92bcb | ||
|
|
65732a58d0 | ||
|
|
ace7f76210 | ||
| fda365bd8b | |||
| c1cfc08c23 | |||
| 150fdddd2a | |||
| 6b659773f1 | |||
| 74d82fa356 | |||
| 3949411c57 | |||
| a455f6b79a | |||
| 2c08687c29 | |||
| 200f1f32f8 | |||
| 768a19b4d6 | |||
|
|
dc718392b6 | ||
|
|
e8f4fef41c | ||
| 6566dd66f0 | |||
| 1593799c03 | |||
| ea3dd75fec | |||
| a306f2c601 | |||
| 82f54c120d | |||
|
|
2d5799e2f2 | ||
| 8e33cadcaa | |||
| 03f3225f24 | |||
| 63c7ef26b6 | |||
|
|
c2e7d8037a | ||
| 323c070caa | |||
| 53cf1e2ebe | |||
| 16c5053752 | |||
| 7d2d9a55d3 | |||
| 14c50b4e63 | |||
| 0e68dc585d | |||
| 6ca835add1 | |||
| 306f583522 | |||
| 9f971ed3b9 | |||
| 2ae2d2b33d | |||
| cf1a555b9b | |||
| 4d894a728b | |||
| 8792c5a40f | |||
| 7ab1a1178a | |||
| 1e44da4f6e | |||
| 59171f0fab | |||
| 8098ccf000 | |||
| 4dc87ac22e | |||
| ef5211e45f | |||
| 1a80e72737 | |||
| 8e765b167f | |||
| 30f4b67538 | |||
| 383b5db47e | |||
| f7d812b372 | |||
| 480f5f617d | |||
| 586e36c181 | |||
|
|
13c789b800 | ||
|
|
81e1394fd2 | ||
|
|
b8099fe389 | ||
|
|
1dc072aa67 | ||
|
|
d92f63ca30 | ||
| 78ccb8f54b | |||
| a29104aeab | |||
|
|
45d9e219a5 | ||
|
|
3eda59beeb | ||
|
|
7ada75c1d6 | ||
| 83d5628430 | |||
| a9bb79b01c | |||
| a718fa388d | |||
| 473feff451 | |||
| 9e2e45715e | |||
| 39609425e5 | |||
| ba2a2e8460 | |||
| 96f7881c16 | |||
|
|
6fccd1287b | ||
| 0f22457961 | |||
| ddfbecaa35 | |||
| 3632de10d7 | |||
| 76b98fb8ad | |||
| f045adf441 | |||
| 811173ddb4 | |||
| 3c910ca08f | |||
| a8c9ede77e | |||
|
|
9eadb941da | ||
|
|
93800f81c1 | ||
|
|
a94a4fd5b0 | ||
| 1acbdbc674 | |||
| 195f685584 | |||
| b72a99748f | |||
| 3cf9310ef7 | |||
| ceae80c91c | |||
| 54add2c801 | |||
| 2d157bf2c0 | |||
| 6f71a028f0 | |||
| dfc7c2e03e | |||
| c443914222 | |||
| eddd4e4180 | |||
| 0d05505493 | |||
|
|
a461dba10d | ||
|
|
ca71f8a572 | ||
| 60230eb1f6 | |||
| 315e8d5363 | |||
| 88d078a535 | |||
| 74ab3a1804 | |||
| 2d8614fa0f | |||
| c8bad4df1a | |||
| 335b2665f2 | |||
| 8552270a68 | |||
| 6f49b76607 | |||
| 4653eaca09 | |||
| 722eea7e7b | |||
| 304f2182ac | |||
| 73908b1661 | |||
| 105ba96757 | |||
| 0681f67bc6 | |||
| 066ddd0d98 | |||
| 417faf3ff2 | |||
| 001021dac8 | |||
| 5c42f7ab9a | |||
| 5e65726cb0 | |||
| 138ae51936 | |||
| b5c802403b | |||
| e54435c2e4 | |||
| 975510c86a | |||
| 9dd2a49d9b | |||
| 90872e0c60 | |||
| baac74eb47 | |||
| 360dd28e20 | |||
| 1e36c148ff | |||
| 399620de98 | |||
| 5d10875a3f | |||
| 4481f59eda | |||
| 1b2f51dcaf | |||
| 0d6de3fe5b | |||
| ec23ae2e76 | |||
| 76930ab45a | |||
| a77e4dbc5a | |||
| 9305f48639 | |||
| da276a1b50 | |||
| dfd3ab9b77 | |||
| d53b32b95e | |||
| 3edbd53ef8 | |||
| 9c49b78593 | |||
| ca87c339b0 | |||
| fd74628259 | |||
| 839f33a7fc | |||
| ebd391df63 | |||
| 752406815c | |||
| 4ec6ccd0fd | |||
| aef545d51e | |||
| 3249e1719f | |||
| f830cc6256 | |||
| 7e01d54b08 | |||
| 487ba6253d | |||
| 745d15b459 | |||
| 8e2ba58ddb | |||
| 6eedb60a6a | |||
| 81fac864f1 | |||
| e868b50c0f | |||
| b9ed7d8cb7 | |||
| 6ae4a1b6d9 | |||
| f890596b4c | |||
| 22ee24cfdf | |||
| 34e2b8d855 | |||
| 196833ed3c | |||
| 85277bbf5e | |||
| 26e50cf908 | |||
| 5be18e27c9 | |||
| 2c410e1cb3 | |||
| 1b622284a1 | |||
| 404481c3dc | |||
| 15f437314a | |||
| 3746c7f326 | |||
| b7b638636d | |||
| dd13300c8b | |||
| a59a6cb7d8 | |||
| d7ea0017b7 | |||
| 09dc1f3e60 | |||
| 43dc4ff031 | |||
| 4596d9d589 | |||
|
|
f2acd2c1b1 | ||
| 76f49a532f | |||
| 3fd2e6ac2f | |||
| 65cbaddd5f | |||
| 9f5fc6924e | |||
| 07b65bcff5 | |||
|
|
2f46716a7a | ||
| e6723a6951 | |||
| 66c4b68036 | |||
| 4ca3a56280 | |||
|
|
487470818c | ||
| 1b1b63caa3 | |||
| d38bae0dd1 | |||
| 282e87d8cc | |||
| a9979714ba | |||
| f4dc6c62e6 | |||
| c8ebf7fde2 | |||
| eda702c914 | |||
| 19dabb7385 | |||
| e617e52127 | |||
| a09f7b59c2 |
31
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
31
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: "[bug-report]"
|
||||
labels: bug
|
||||
assignees: TLINDEN
|
||||
|
||||
---
|
||||
|
||||
**Description**
|
||||
<!-- Please provide a clear and concise description of the issue: -->
|
||||
|
||||
|
||||
**Steps To Reproduce**
|
||||
<!-- Please detail the steps to reproduce the behavior: -->
|
||||
|
||||
|
||||
**Expected behavior**
|
||||
<!-- What do you expected to happen instead? -->
|
||||
|
||||
|
||||
**Version information**
|
||||
<!--
|
||||
Please provide as much version information as possible:
|
||||
- if you have just installed a binary, provide the output of: tablizer --version
|
||||
- if you installed from source, provide the output of: make show-version
|
||||
- provide additional details: operating system and version and shell environment
|
||||
-->
|
||||
|
||||
|
||||
**Additional informations**
|
||||
23
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
23
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest a feature
|
||||
title: "[feature-request]"
|
||||
labels: feature-request
|
||||
assignees: TLINDEN
|
||||
|
||||
---
|
||||
|
||||
**Description**
|
||||
<!-- Please provide a clear and concise description of the feature you desire: -->
|
||||
|
||||
|
||||
|
||||
**Version information**
|
||||
<!--
|
||||
Just in case the feature is already present, please provide as
|
||||
much version information as possible:
|
||||
- if you have just installed a binary, provide the output of: tablizer --version
|
||||
- if you installed from source, provide the output of: make show-version
|
||||
- provide additional details: operating system and version and shell environment
|
||||
-->
|
||||
|
||||
10
.github/dependabot.yml
vendored
Normal file
10
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "gomod"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
releases
|
||||
tablizer
|
||||
*.out
|
||||
46
Makefile
46
Makefile
@@ -1,46 +0,0 @@
|
||||
|
||||
# Copyright © 2022 Thomas von Dein
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#
|
||||
# no need to modify anything below
|
||||
tool = tablizer
|
||||
version = $(shell egrep "^var version = " cmd/root.go | cut -d'=' -f2 | cut -d'"' -f 2)
|
||||
archs = android darwin freebsd linux netbsd openbsd windows
|
||||
PREFIX = /usr/local
|
||||
UID = root
|
||||
GID = 0
|
||||
|
||||
all: buildlocal man
|
||||
|
||||
man:
|
||||
pod2man -c "User Commands" -r 1 -s 1 $(tool).pod > $(tool).1
|
||||
|
||||
buildlocal:
|
||||
go build
|
||||
|
||||
release:
|
||||
mkdir -p releases
|
||||
$(foreach arch,$(archs), GOOS=$(arch) GOARCH=amd64 go build -x -o releases/$(tool)-$(arch)-amd64-$(version); sha256sum releases/$(tool)-$(arch)-amd64-$(version) | cut -d' ' -f1 > releases/$(tool)-$(arch)-amd64-$(version).sha256sum;)
|
||||
|
||||
install: buildlocal
|
||||
install -d -o $(UID) -g $(GID) $(PREFIX)/bin
|
||||
install -d -o $(UID) -g $(GID) $(PREFIX)/man/man1
|
||||
install -o $(UID) -g $(GID) -m 555 $(tool) $(PREFIX)/sbin/
|
||||
install -o $(UID) -g $(GID) -m 444 $(tool).1 $(PREFIX)/man/man1/
|
||||
|
||||
clean:
|
||||
rm -f $(tool) $(tool).1
|
||||
221
README.md
221
README.md
@@ -1,8 +1,93 @@
|
||||
[](https://ci.codeberg.org/repos/15519)
|
||||
[](https://codeberg.org/scip/tablizer/blob/master/LICENSE)
|
||||
[](https://goreportcard.com/report/codeberg.org/scip/tablizer)
|
||||
|
||||
## tablizer - Manipulate tabular output of other programs
|
||||
|
||||
> [!IMPORTANT]
|
||||
> This software is now being maintained on [Codeberg](https://codeberg.org/scip/tablizer/).
|
||||
|
||||
Tablizer can be used to re-format tabular output of other
|
||||
programs. While you could do this using standard unix tools, in some
|
||||
cases it's a hard job.
|
||||
cases it's a hard job. With tablizer you can filter by column[s],
|
||||
ignore certain column[s] by regex, name or number. It can output the
|
||||
tabular data in a range of formats (see below). There's even an
|
||||
interactive filter/selection tool available.
|
||||
|
||||
## FEATURES
|
||||
|
||||
- supports csv, json or ascii format input from files or stdin
|
||||
- split any tabular input data by character or regular expression into columns
|
||||
- add headers if input data doesn't contain them (automatically or manually)
|
||||
- print tabular data as ascii table, org-mode, markdown, csv, shell-evaluable or yaml format
|
||||
- filter rows by regular expression (saves a call to `| grep ...`)
|
||||
- filter rows by column filter
|
||||
- filters may also be negations eg `-Fname!=cow.*` or `-v`
|
||||
- modify cells wih regular expressions
|
||||
- reduce columns by specifying which columns to show, with regex support
|
||||
- color support
|
||||
- sort by any field[s], multiple sort modes are supported
|
||||
- shell completion for options
|
||||
- regular used options can be put into a config file
|
||||
- filter TUI where where you can interactively sort and filter rows
|
||||
|
||||
## Demo
|
||||
|
||||

|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```default
|
||||
Usage:
|
||||
tablizer [regex,...] [file, ...] [flags]
|
||||
|
||||
Operational Flags:
|
||||
-c, --columns string Only show the speficied columns (separated by ,)
|
||||
-v, --invert-match select non-matching rows
|
||||
-n, --numbering Enable header numbering
|
||||
-N, --no-color Disable pattern highlighting
|
||||
-H, --no-headers Disable headers display
|
||||
-s, --separator <string> Custom field separator
|
||||
-k, --sort-by <int|name> Sort by column (default: 1)
|
||||
-z, --fuzzy Use fuzzy search [experimental]
|
||||
-F, --filter <field[!]=reg> Filter given field with regex, can be used multiple times
|
||||
-T, --transpose-columns string Transpose the speficied columns (separated by ,)
|
||||
-R, --regex-transposer </from/to/> Apply /search/replace/ regexp to fields given in -T
|
||||
-j, --json Read JSON input (must be array of hashes)
|
||||
-I, --interactive Interactively filter and select rows
|
||||
--auto-headers Generate headers if there are none present in input
|
||||
--custom-headers a,b,... Use custom headers, separated by comma
|
||||
|
||||
|
||||
Output Flags (mutually exclusive):
|
||||
-X, --extended Enable extended output
|
||||
-M, --markdown Enable markdown table output
|
||||
-O, --orgtbl Enable org-mode table output
|
||||
-S, --shell Enable shell evaluable output
|
||||
-Y, --yaml Enable yaml output
|
||||
-C, --csv Enable CSV output
|
||||
-A, --ascii Default output mode, ascii tabular
|
||||
-L, --hightlight-lines Use alternating background colors for tables
|
||||
-y, --yank-columns Yank specified columns (separated by ,) to clipboard,
|
||||
space separated
|
||||
--ofs <char> Output field separator, used by -A and -C.
|
||||
|
||||
Sort Mode Flags (mutually exclusive):
|
||||
-a, --sort-age sort according to age (duration) string
|
||||
-D, --sort-desc Sort in descending order (default: ascending)
|
||||
-i, --sort-numeric sort according to string numerical value
|
||||
-t, --sort-time sort according to time string
|
||||
|
||||
Other Flags:
|
||||
-r --read-file <file> Use <file> as input instead of STDIN
|
||||
--completion <shell> Generate the autocompletion script for <shell>
|
||||
-f, --config <file> Configuration file (default: ~/.config/tablizer/config)
|
||||
-d, --debug Enable debugging
|
||||
-h, --help help for tablizer
|
||||
-m, --man Display manual page
|
||||
-V, --version Print program version
|
||||
```
|
||||
|
||||
Let's take this output:
|
||||
```
|
||||
@@ -17,41 +102,42 @@ But you're only interested in the NAME and STATUS columns. Here's how
|
||||
to do this with tablizer:
|
||||
|
||||
```
|
||||
% kubectl get pods | ./tablizer
|
||||
NAME(1) READY(2) STATUS(3) RESTARTS(4) AGE(5)
|
||||
% kubectl get pods | tablizer
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
repldepl-7bcd8d5b64-7zq4l 1/1 Running 1 (69m ago) 5h26m
|
||||
repldepl-7bcd8d5b64-m48n8 1/1 Running 1 (69m ago) 5h26m
|
||||
repldepl-7bcd8d5b64-q2bf4 1/1 Running 1 (69m ago) 5h26m
|
||||
|
||||
% kubectl get pods | ./tablizer -c 1,3
|
||||
NAME(1) STATUS(3)
|
||||
% kubectl get pods | tablizer -c 1,3
|
||||
NAME STATUS
|
||||
repldepl-7bcd8d5b64-7zq4l Running
|
||||
repldepl-7bcd8d5b64-m48n8 Running
|
||||
repldepl-7bcd8d5b64-q2bf4 Running
|
||||
```
|
||||
|
||||
Another use case is when the tabular output is so wide that lines are
|
||||
being broken and the whole output is completely distorted. In such a
|
||||
case you can use the `-x` flag to get an output similar to `\x` in `psql`:
|
||||
being broken and the whole output is completely distorted. In such a
|
||||
case you can use the `-o extended | -X` flag to get an output similar
|
||||
to `\x` in `psql`:
|
||||
|
||||
```
|
||||
% kubectl get pods | ./tablizer -x
|
||||
NAME: repldepl-7bcd8d5b64-7zq4l
|
||||
READY: 1/1
|
||||
STATUS: Running
|
||||
RESTARTS: 1 (71m ago)
|
||||
% kubectl get pods | tablizer -X
|
||||
NAME: repldepl-7bcd8d5b64-7zq4l
|
||||
READY: 1/1
|
||||
STATUS: Running
|
||||
RESTARTS: 1 (71m ago)
|
||||
AGE: 5h28m
|
||||
|
||||
NAME: repldepl-7bcd8d5b64-m48n8
|
||||
READY: 1/1
|
||||
STATUS: Running
|
||||
RESTARTS: 1 (71m ago)
|
||||
NAME: repldepl-7bcd8d5b64-m48n8
|
||||
READY: 1/1
|
||||
STATUS: Running
|
||||
RESTARTS: 1 (71m ago)
|
||||
AGE: 5h28m
|
||||
|
||||
NAME: repldepl-7bcd8d5b64-q2bf4
|
||||
READY: 1/1
|
||||
STATUS: Running
|
||||
RESTARTS: 1 (71m ago)
|
||||
NAME: repldepl-7bcd8d5b64-q2bf4
|
||||
READY: 1/1
|
||||
STATUS: Running
|
||||
RESTARTS: 1 (71m ago)
|
||||
AGE: 5h28m
|
||||
```
|
||||
|
||||
@@ -60,17 +146,56 @@ Tablize can read one or more files or - if none specified - from STDIN.
|
||||
You can also specify a regex pattern to reduce the output:
|
||||
|
||||
```
|
||||
% kubectl get pods | ./tablizer q2bf4
|
||||
NAME(1) READY(2) STATUS(3) RESTARTS(4) AGE(5)
|
||||
% kubectl get pods | tablizer q2bf4
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
repldepl-7bcd8d5b64-q2bf4 1/1 Running 1 (69m ago) 5h26m
|
||||
```
|
||||
|
||||
Sometimes a filter regex is to broad and you wish to filter only on a
|
||||
particular column. This is possible using `-F`:
|
||||
```
|
||||
% kubectl get pods | tablizer -Fname=2
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
repldepl-7bcd8d5b64-q2bf4 1/1 Running 1 (69m ago) 5h26m
|
||||
```
|
||||
|
||||
Here we filtered the `NAME` column for `2`, which would have matched
|
||||
otherwise on all rows.
|
||||
|
||||
There are more output modes like org-mode (orgtbl) and markdown.
|
||||
|
||||
You can also use it to modify certain cells using regular expression
|
||||
matching. For example:
|
||||
|
||||
```shell
|
||||
kubectl get pods | tablizer -T4 -R '/ /-/'
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
repldepl-7bcd8d5b64-7zq4l 1/1 Running 1-(69m-ago) 5h26m
|
||||
repldepl-7bcd8d5b64-m48n8 1/1 Running 1-(69m-ago) 5h26m
|
||||
repldepl-7bcd8d5b64-q2bf4 1/1 Running 1-(69m-ago) 5h26m
|
||||
```
|
||||
|
||||
Here, we modified the 4th column (`-T4`) by replacing every space with
|
||||
a dash. If you need to work with `/` characters, you can also use any
|
||||
other separator, for instance: `-R '| |-|'`.
|
||||
|
||||
There's also an interactive mode, invoked with the option B<-I>, where
|
||||
you can interactively filter and select rows:
|
||||
|
||||
<img width="937" height="293" alt="interactive" src="https://github.com/user-attachments/assets/0d4d65e2-d156-43ed-8021-39047c7939ed" />
|
||||
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
There are multiple ways to install **tablizer**:
|
||||
|
||||
- Go to the [latest release page](https://github.com/muesli/mango/releases/latest),
|
||||
- You can use [stew](https://github.com/marwanhawari/stew) to install tablizer:
|
||||
```default
|
||||
stew install tlinden/tablizer
|
||||
```
|
||||
|
||||
- Go to the [latest release page](https://codeberg.org/scip/tablizer/releases),
|
||||
locate the binary for your operating system and platform.
|
||||
|
||||
Download it and put it into some directory within your `$PATH` variable.
|
||||
@@ -83,7 +208,7 @@ There are multiple ways to install **tablizer**:
|
||||
|
||||
- You can also install from source. Issue the following commands in your shell:
|
||||
```
|
||||
git clone https://github.com/TLINDEN/tablizer.git
|
||||
git clone https://codeberg.org/scip/tablizer.git
|
||||
cd tablizer
|
||||
make
|
||||
sudo make install
|
||||
@@ -95,14 +220,17 @@ hesitate to ask me about it, I'll add it.
|
||||
## Documentation
|
||||
|
||||
The documentation is provided as a unix man-page. It will be
|
||||
automatically installed if you install from source. However, you can
|
||||
read the man-page online:
|
||||
automatically installed if you install from source.
|
||||
|
||||
https://github.com/TLINDEN/tablizer/blob/main/tablizer.pod
|
||||
[However, you can read the man-page online](https://codeberg.org/scip/tablizer/raw/branch/tablizer.pod).
|
||||
|
||||
Or if you cloned the repository you can read it this way (perl needs
|
||||
to be installed though): `perldoc tablizer.pod`.
|
||||
|
||||
If you have the binary installed, you can also read the man page with
|
||||
this command:
|
||||
|
||||
tablizer --man
|
||||
|
||||
## Getting help
|
||||
|
||||
@@ -111,7 +239,42 @@ that's the best way for me to forget to do something.
|
||||
|
||||
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.
|
||||
https://codeberg.org/scip/tablizer/issues.
|
||||
|
||||
## Prior Art
|
||||
|
||||
When I started with tablizer I was not aware that other tools
|
||||
exist. Here is a non-exhausive list of the ones I find especially
|
||||
awesome:
|
||||
|
||||
### [miller](https://github.com/johnkerl/miller)
|
||||
|
||||
This is a really powerful tool to work with tabular data and it also
|
||||
allows other inputs as json, csv etc. You can filter, manipulate,
|
||||
create pipelines, there's even a programming language builtin to do
|
||||
even more amazing things.
|
||||
|
||||
### [csvq](https://github.com/mithrandie/csvq)
|
||||
|
||||
Csvq allows you to query CSV and TSV data using SQL queries. How nice
|
||||
is that? Highly recommended if you have to work with a large (and
|
||||
wide) dataset and need to apply a complicated set of rules.
|
||||
|
||||
### [goawk](https://github.com/benhoyt/goawk)
|
||||
|
||||
Goawk is a 100% POSIX compliant AWK implementation in GO, which also
|
||||
supports CSV and TSV data as input (using `-i csv` for example). You
|
||||
can apply any kind of awk code to your tabular data, there are no
|
||||
limit to your creativity!
|
||||
|
||||
### [teip](https://github.com/greymd/teip)
|
||||
|
||||
I particularly like teip, it's a real gem. You can use it to drill
|
||||
"holes" into your tabular data and modify these "holes" using small
|
||||
external unix commands such as grep or sed. The possibilities are
|
||||
endless, you can even use teip to modify data inside a hole created by
|
||||
teip. Highly recommended.
|
||||
|
||||
|
||||
## Copyright and license
|
||||
|
||||
@@ -123,4 +286,4 @@ T.v.Dein <tom AT vondein DOT org>
|
||||
|
||||
## Project homepage
|
||||
|
||||
https://github.com/TLINDEN/tablizer
|
||||
https://codeberg.org/scip/tablizer
|
||||
|
||||
6
TODO
6
TODO
@@ -1,6 +0,0 @@
|
||||
Add a mode like FreeBSD stat(1):
|
||||
|
||||
stat -s dead.letter
|
||||
st_dev=170671546954750497 st_ino=159667 st_mode=0100644 st_nlink=1 st_uid=1001 st_gid=1001 st_rdev=18446744073709551615 st_size=573 st_atime=1661994007 st_mtime=1661961878 st_ctime=1661961878 st_birthtime=1658394900 st_blksize=4096 st_blocks=3 st_flags=2048
|
||||
|
||||
Add reasoning about non-csv output of kubectl
|
||||
169
cmd/parser.go
169
cmd/parser.go
@@ -1,169 +0,0 @@
|
||||
/*
|
||||
Copyright © 2022 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// contains a whole parsed table
|
||||
type Tabdata struct {
|
||||
maxwidthHeader int // longest header
|
||||
maxwidthPerCol []int // max width per column
|
||||
columns int
|
||||
headerIndices []map[string]int // [ {beg=>0, end=>17}, ... ]
|
||||
headers []string // [ "ID", "NAME", ...]
|
||||
entries [][]string
|
||||
}
|
||||
|
||||
func die(v ...interface{}) {
|
||||
fmt.Fprintln(os.Stderr, v...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
/*
|
||||
Parse tabular input. We split the header (first line) by 2 or more
|
||||
spaces, remember the positions of the header fields. We then split
|
||||
the data (everything after the first line) by those positions. That
|
||||
way we can turn "tabular data" (with fields containing whitespaces)
|
||||
into real tabular data. We re-tabulate our input if you will.
|
||||
*/
|
||||
func parseFile(input io.Reader, pattern string) Tabdata {
|
||||
data := Tabdata{}
|
||||
|
||||
var scanner *bufio.Scanner
|
||||
var spaces = `\s\s+|$`
|
||||
|
||||
if len(Separator) > 0 {
|
||||
spaces = Separator
|
||||
}
|
||||
|
||||
hadFirst := false
|
||||
spacefinder := regexp.MustCompile(spaces)
|
||||
beg := 0
|
||||
|
||||
scanner = bufio.NewScanner(input)
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
values := []string{}
|
||||
|
||||
patternR, err := regexp.Compile(pattern)
|
||||
if err != nil {
|
||||
die(err)
|
||||
}
|
||||
|
||||
if !hadFirst {
|
||||
// header processing
|
||||
parts := spacefinder.FindAllStringIndex(line, -1)
|
||||
data.columns = len(parts)
|
||||
// if Debug {
|
||||
// fmt.Println(parts)
|
||||
// }
|
||||
|
||||
// process all header fields
|
||||
for _, part := range parts {
|
||||
// if Debug {
|
||||
// fmt.Printf("Part: <%s>\n", string(line[beg:part[0]]))
|
||||
//}
|
||||
|
||||
// current field
|
||||
head := string(line[beg:part[0]])
|
||||
|
||||
// register begin and end of field within line
|
||||
indices := make(map[string]int)
|
||||
indices["beg"] = beg
|
||||
if part[0] == part[1] {
|
||||
indices["end"] = 0
|
||||
} else {
|
||||
indices["end"] = part[1] - 1
|
||||
}
|
||||
|
||||
// register widest header field
|
||||
headerlen := len(head)
|
||||
if headerlen > data.maxwidthHeader {
|
||||
data.maxwidthHeader = headerlen
|
||||
}
|
||||
|
||||
// register fields data
|
||||
data.headerIndices = append(data.headerIndices, indices)
|
||||
data.headers = append(data.headers, head)
|
||||
|
||||
// end of current field == begin of next one
|
||||
beg = part[1]
|
||||
|
||||
// done
|
||||
hadFirst = true
|
||||
}
|
||||
// if Debug {
|
||||
// fmt.Println(data.headerIndices)
|
||||
// }
|
||||
} else {
|
||||
// data processing
|
||||
if len(pattern) > 0 {
|
||||
//fmt.Println(patternR.MatchString(line))
|
||||
if !patternR.MatchString(line) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
idx := 0 // we cannot use the header index, because we could exclude columns
|
||||
|
||||
for _, index := range data.headerIndices {
|
||||
value := ""
|
||||
if index["end"] == 0 {
|
||||
value = string(line[index["beg"]:])
|
||||
} else {
|
||||
value = string(line[index["beg"]:index["end"]])
|
||||
}
|
||||
|
||||
width := len(strings.TrimSpace(value))
|
||||
|
||||
if len(data.maxwidthPerCol)-1 < idx {
|
||||
data.maxwidthPerCol = append(data.maxwidthPerCol, width)
|
||||
} else {
|
||||
if width > data.maxwidthPerCol[idx] {
|
||||
data.maxwidthPerCol[idx] = width
|
||||
}
|
||||
}
|
||||
|
||||
// if Debug {
|
||||
// fmt.Printf("<%s> ", value)
|
||||
// }
|
||||
values = append(values, value)
|
||||
|
||||
idx++
|
||||
}
|
||||
if Debug {
|
||||
fmt.Println()
|
||||
}
|
||||
data.entries = append(data.entries, values)
|
||||
}
|
||||
}
|
||||
|
||||
if scanner.Err() != nil {
|
||||
die(scanner.Err())
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
126
cmd/printer.go
126
cmd/printer.go
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
Copyright © 2022 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func printTable(data Tabdata) {
|
||||
if XtendedOut {
|
||||
printExtended(data)
|
||||
return
|
||||
}
|
||||
|
||||
// needed for data output
|
||||
var formats []string
|
||||
|
||||
if len(data.entries) > 0 {
|
||||
// headers
|
||||
for i, head := range data.headers {
|
||||
if len(Columns) > 0 {
|
||||
if !contains(UseColumns, i+1) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// calculate column width
|
||||
var width int
|
||||
var iwidth int
|
||||
var format string
|
||||
|
||||
// generate format string
|
||||
if len(head) > data.maxwidthPerCol[i] {
|
||||
width = len(head)
|
||||
} else {
|
||||
width = data.maxwidthPerCol[i]
|
||||
}
|
||||
|
||||
if NoNumbering {
|
||||
iwidth = 0
|
||||
} else {
|
||||
iwidth = len(fmt.Sprintf("%d", i)) // in case i > 9
|
||||
}
|
||||
|
||||
format = fmt.Sprintf("%%-%ds", 3+iwidth+width)
|
||||
|
||||
if NoNumbering {
|
||||
fmt.Printf(format, fmt.Sprintf("%s ", head))
|
||||
} else {
|
||||
fmt.Printf(format, fmt.Sprintf("%s(%d) ", head, i+1))
|
||||
}
|
||||
|
||||
// register
|
||||
formats = append(formats, format)
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
// entries
|
||||
var idx int
|
||||
for _, entry := range data.entries {
|
||||
idx = 0
|
||||
//fmt.Println(entry)
|
||||
for i, value := range entry {
|
||||
if len(Columns) > 0 {
|
||||
if !contains(UseColumns, i+1) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
fmt.Printf(formats[idx], strings.TrimSpace(value))
|
||||
idx++
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
We simulate the \x command of psql (the PostgreSQL client)
|
||||
*/
|
||||
func printExtended(data Tabdata) {
|
||||
// needed for data output
|
||||
format := fmt.Sprintf("%%%ds: %%s\n", data.maxwidthHeader) // FIXME: re-calculate if -c has been set
|
||||
|
||||
if len(data.entries) > 0 {
|
||||
var idx int
|
||||
for _, entry := range data.entries {
|
||||
idx = 0
|
||||
for i, value := range entry {
|
||||
if len(Columns) > 0 {
|
||||
if !contains(UseColumns, i+1) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf(format, data.headers[idx], value)
|
||||
idx++
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func contains(s []int, e int) bool {
|
||||
for _, a := range s {
|
||||
if a == e {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
Copyright © 2022 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/alecthomas/repr"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func process(args []string) error {
|
||||
var pattern string
|
||||
havefiles := false
|
||||
|
||||
if len(Columns) > 0 {
|
||||
for _, use := range strings.Split(Columns, ",") {
|
||||
usenum, err := strconv.Atoi(use)
|
||||
if err != nil {
|
||||
die(err)
|
||||
}
|
||||
UseColumns = append(UseColumns, usenum)
|
||||
}
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
if _, err := os.Stat(args[0]); err != nil {
|
||||
pattern = args[0]
|
||||
args = args[1:]
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
for _, file := range args {
|
||||
fd, err := os.OpenFile(file, os.O_RDONLY, 0755)
|
||||
if err != nil {
|
||||
die(err)
|
||||
}
|
||||
|
||||
data := parseFile(fd, pattern)
|
||||
if Debug {
|
||||
repr.Print(data)
|
||||
}
|
||||
printTable(data)
|
||||
}
|
||||
havefiles = true
|
||||
}
|
||||
}
|
||||
|
||||
if !havefiles {
|
||||
stat, _ := os.Stdin.Stat()
|
||||
if (stat.Mode() & os.ModeCharDevice) == 0 {
|
||||
data := parseFile(os.Stdin, pattern)
|
||||
if Debug {
|
||||
repr.Print(data)
|
||||
}
|
||||
printTable(data)
|
||||
} else {
|
||||
return errors.New("No file specified and nothing to read on stdin!")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
63
cmd/root.go
63
cmd/root.go
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
Copyright © 2022 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
)
|
||||
|
||||
var version = "v1.0.1"
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "tablizer [regex] [file, ...]",
|
||||
Short: "[Re-]tabularize tabular data",
|
||||
Long: `Manipulate tabular output of other programs`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if Version {
|
||||
fmt.Printf("This is tablizer version %s\n", version)
|
||||
return nil
|
||||
}
|
||||
|
||||
return process(args)
|
||||
},
|
||||
}
|
||||
|
||||
var Debug bool
|
||||
var XtendedOut bool
|
||||
var NoNumbering bool
|
||||
var Version bool
|
||||
var Columns string
|
||||
var UseColumns []int
|
||||
var Separator string
|
||||
|
||||
func Execute() {
|
||||
err := rootCmd.Execute()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().BoolVarP(&Debug, "debug", "d", false, "Enable debugging")
|
||||
rootCmd.PersistentFlags().BoolVarP(&XtendedOut, "extended", "x", false, "Enable extended output")
|
||||
rootCmd.PersistentFlags().BoolVarP(&NoNumbering, "no-numbering", "n", false, "Disable header numbering")
|
||||
rootCmd.PersistentFlags().BoolVarP(&Version, "version", "v", false, "Print program version")
|
||||
rootCmd.PersistentFlags().StringVarP(&Separator, "separator", "s", "", "Custom field separator")
|
||||
rootCmd.PersistentFlags().StringVarP(&Columns, "columns", "c", "", "Only show the speficied columns (separated by ,)")
|
||||
}
|
||||
12
go.mod
12
go.mod
@@ -1,12 +0,0 @@
|
||||
module daemon.de/tablizer
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897
|
||||
|
||||
require (
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
github.com/spf13/cobra v1.5.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/stretchr/testify v1.8.0 // indirect
|
||||
)
|
||||
25
go.sum
25
go.sum
@@ -1,25 +0,0 @@
|
||||
github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897 h1:p9Sln00KOTlrYkxI1zYWl1QLnEqAqEARBEYa8FQnQcY=
|
||||
github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
|
||||
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
26
main.go
26
main.go
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
Copyright © 2022 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"daemon.de/tablizer/cmd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cmd.Execute()
|
||||
}
|
||||
60
mkrel.sh
60
mkrel.sh
@@ -1,60 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright © 2022 Thomas von Dein
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
# get list with: go tool dist list
|
||||
DIST="darwin/amd64
|
||||
freebsd/amd64
|
||||
linux/amd64
|
||||
netbsd/amd64
|
||||
openbsd/amd64
|
||||
windows/amd64"
|
||||
|
||||
tool="$1"
|
||||
version="$2"
|
||||
|
||||
rm -rf releases
|
||||
mkdir -p releases
|
||||
|
||||
|
||||
for D in $DIST; do
|
||||
os=${D/\/*/}
|
||||
arch=${D/*\//}
|
||||
binfile="releases/${tool}-${os}-${arch}-${version}"
|
||||
tardir="${tool}-${os}-${arch}-${version}"
|
||||
tarfile="releases/${tool}-${os}-${arch}-${version}.tar.gz"
|
||||
set -x
|
||||
GOOS=${os} GOARCH=${arch} go build -o ${binfile}
|
||||
mkdir -p ${tardir}
|
||||
cp ${binfile} README.md LICENSE ${tardir}/
|
||||
echo 'tool = tablizer
|
||||
PREFIX = /usr/local
|
||||
UID = root
|
||||
GID = 0
|
||||
|
||||
install:
|
||||
install -d -o $(UID) -g $(GID) $(PREFIX)/bin
|
||||
install -d -o $(UID) -g $(GID) $(PREFIX)/man/man1
|
||||
install -o $(UID) -g $(GID) -m 555 $(tool) $(PREFIX)/sbin/
|
||||
install -o $(UID) -g $(GID) -m 444 $(tool).1 $(PREFIX)/man/man1/' > ${tardir}/Makefile
|
||||
tar cpzf ${tarfile} ${tardir}
|
||||
sha256sum ${binfile} | cut -d' ' -f1 > ${binfile}.sha256
|
||||
sha256sum ${tarfile} | cut -d' ' -f1 > ${tarfile}.sha256
|
||||
rm -rf ${tardir}
|
||||
set +x
|
||||
done
|
||||
|
||||
122
tablizer.pod
122
tablizer.pod
@@ -1,122 +0,0 @@
|
||||
=head1 NAME
|
||||
|
||||
tablizer - Manipulate tabular output of other programs
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
Usage:
|
||||
tablizer [regex] [file, ...] [flags]
|
||||
|
||||
Flags:
|
||||
-c, --columns string Only show the speficied columns (separated by ,)
|
||||
-d, --debug Enable debugging
|
||||
-x, --extended Enable extended output
|
||||
-h, --help help for tablizer
|
||||
-n, --no-numbering Disable header numbering
|
||||
-s, --separator string Custom field separator
|
||||
-v, --version Print program version
|
||||
|
||||
|
||||
=head1 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 B<tablizer> to do these and more things.
|
||||
|
||||
B<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 C<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
|
||||
parameters. 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 B<-n> option.
|
||||
|
||||
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 B<-x> option can be usefull which enables
|
||||
I<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 -x
|
||||
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.
|
||||
|
||||
Finally the B<-d> option enables debugging output which is mostly
|
||||
usefull for the developer.
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
In order to report a bug, unexpected behavior, feature requests
|
||||
or to submit a patch, please open an issue on github:
|
||||
L<https://github.com/TLINDEN/tablizer/issues>.
|
||||
|
||||
=head1 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:
|
||||
|
||||
=over 4
|
||||
|
||||
=item repr (https://github.com/alecthomas/repr)
|
||||
|
||||
Released under the MIT License, Copyright (c) 2016 Alec Thomas
|
||||
|
||||
=item cobra (https://github.com/spf13/cobra)
|
||||
|
||||
Released under the Apache 2.0 license, Copyright 2013-2022 The Cobra Authors
|
||||
|
||||
=back
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
Thomas von Dein B<tom AT vondein DOT org>
|
||||
|
||||
=cut
|
||||
|
||||
Reference in New Issue
Block a user