Skip to content
This repository was archived by the owner on Dec 13, 2025. It is now read-only.

Commit 5f3f7c4

Browse files
authored
Improve ascii table, add --ofs flag, enhance documentation (#67)
* enhanced documentation * added --ofs parameter use 2 spaces for ascii output but it is customizable with --ofs, which is also being used by CSV mode (whose defaults remains unchanged) * improve ascii table output, use 2 spaces as OFS by default
1 parent 687f4b7 commit 5f3f7c4

File tree

8 files changed

+249
-192
lines changed

8 files changed

+249
-192
lines changed

README.md

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,44 +23,46 @@ Usage:
2323
tablizer [regex,...] [file, ...] [flags]
2424
2525
Operational Flags:
26-
-c, --columns string Only show the speficied columns (separated by ,)
27-
-v, --invert-match select non-matching rows
28-
-n, --numbering Enable header numbering
29-
-N, --no-color Disable pattern highlighting
30-
-H, --no-headers Disable headers display
31-
-s, --separator string Custom field separator
32-
-k, --sort-by int|name Sort by column (default: 1)
33-
-z, --fuzzy Use fuzzy search [experimental]
34-
-F, --filter field[!]=reg Filter given field with regex, can be used multiple times
35-
-T, --transpose-columns string Transpose the speficied columns (separated by ,)
36-
-R, --regex-transposer /from/to/ Apply /search/replace/ regexp to fields given in -T
37-
-I, --interactive Interactively filter and select rows
26+
-c, --columns string Only show the speficied columns (separated by ,)
27+
-v, --invert-match select non-matching rows
28+
-n, --numbering Enable header numbering
29+
-N, --no-color Disable pattern highlighting
30+
-H, --no-headers Disable headers display
31+
-s, --separator <string> Custom field separator
32+
-k, --sort-by <int|name> Sort by column (default: 1)
33+
-z, --fuzzy Use fuzzy search [experimental]
34+
-F, --filter <field[!]=reg> Filter given field with regex, can be used multiple times
35+
-T, --transpose-columns string Transpose the speficied columns (separated by ,)
36+
-R, --regex-transposer </from/to/> Apply /search/replace/ regexp to fields given in -T
37+
-I, --interactive Interactively filter and select rows
3838
3939
Output Flags (mutually exclusive):
40-
-X, --extended Enable extended output
41-
-M, --markdown Enable markdown table output
42-
-O, --orgtbl Enable org-mode table output
43-
-S, --shell Enable shell evaluable output
44-
-Y, --yaml Enable yaml output
45-
-C, --csv Enable CSV output
46-
-A, --ascii Default output mode, ascii tabular
47-
-L, --hightlight-lines Use alternating background colors for tables
48-
-y, --yank-columns Yank specified columns (separated by ,) to clipboard,
49-
space separated
40+
-X, --extended Enable extended output
41+
-M, --markdown Enable markdown table output
42+
-O, --orgtbl Enable org-mode table output
43+
-S, --shell Enable shell evaluable output
44+
-Y, --yaml Enable yaml output
45+
-C, --csv Enable CSV output
46+
-A, --ascii Default output mode, ascii tabular
47+
-L, --hightlight-lines Use alternating background colors for tables
48+
-y, --yank-columns Yank specified columns (separated by ,) to clipboard,
49+
space separated
50+
--ofs <char> Output field separator, used by -A and -C.
5051
5152
Sort Mode Flags (mutually exclusive):
52-
-a, --sort-age sort according to age (duration) string
53-
-D, --sort-desc Sort in descending order (default: ascending)
54-
-i, --sort-numeric sort according to string numerical value
55-
-t, --sort-time sort according to time string
53+
-a, --sort-age sort according to age (duration) string
54+
-D, --sort-desc Sort in descending order (default: ascending)
55+
-i, --sort-numeric sort according to string numerical value
56+
-t, --sort-time sort according to time string
5657
5758
Other Flags:
58-
--completion <shell> Generate the autocompletion script for <shell>
59-
-f, --config <file> Configuration file (default: ~/.config/tablizer/config)
60-
-d, --debug Enable debugging
61-
-h, --help help for tablizer
62-
-m, --man Display manual page
63-
-V, --version Print program version
59+
-r --read-file <file> Use <file> as input instead of STDIN
60+
--completion <shell> Generate the autocompletion script for <shell>
61+
-f, --config <file> Configuration file (default: ~/.config/tablizer/config)
62+
-d, --debug Enable debugging
63+
-h, --help help for tablizer
64+
-m, --man Display manual page
65+
-V, --version Print program version
6466
```
6567

6668
Let's take this output:
@@ -77,13 +79,13 @@ to do this with tablizer:
7779

7880
```
7981
% kubectl get pods | tablizer
80-
NAME(1) READY(2) STATUS(3) RESTARTS(4) AGE(5)
82+
NAME READY STATUS RESTARTS AGE
8183
repldepl-7bcd8d5b64-7zq4l 1/1 Running 1 (69m ago) 5h26m
8284
repldepl-7bcd8d5b64-m48n8 1/1 Running 1 (69m ago) 5h26m
8385
repldepl-7bcd8d5b64-q2bf4 1/1 Running 1 (69m ago) 5h26m
8486
8587
% kubectl get pods | tablizer -c 1,3
86-
NAME(1) STATUS(3)
88+
NAME STATUS
8789
repldepl-7bcd8d5b64-7zq4l Running
8890
repldepl-7bcd8d5b64-m48n8 Running
8991
repldepl-7bcd8d5b64-q2bf4 Running
@@ -121,14 +123,14 @@ You can also specify a regex pattern to reduce the output:
121123

122124
```
123125
% kubectl get pods | tablizer q2bf4
124-
NAME(1) READY(2) STATUS(3) RESTARTS(4) AGE(5)
126+
NAME READY STATUS RESTARTS AGE
125127
repldepl-7bcd8d5b64-q2bf4 1/1 Running 1 (69m ago) 5h26m
126128
```
127129

128130
Sometimes a filter regex is to broad and you wish to filter only on a
129131
particular column. This is possible using `-F`:
130132
```
131-
% kubectl get pods | tablizer -n -Fname=2
133+
% kubectl get pods | tablizer -Fname=2
132134
NAME READY STATUS RESTARTS AGE
133135
repldepl-7bcd8d5b64-q2bf4 1/1 Running 1 (69m ago) 5h26m
134136
```
@@ -142,7 +144,7 @@ You can also use it to modify certain cells using regular expression
142144
matching. For example:
143145

144146
```shell
145-
kubectl get pods | tablizer -n -T4 -R '/ /-/'
147+
kubectl get pods | tablizer -T4 -R '/ /-/'
146148
NAME READY STATUS RESTARTS AGE
147149
repldepl-7bcd8d5b64-7zq4l 1/1 Running 1-(69m-ago) 5h26m
148150
repldepl-7bcd8d5b64-m48n8 1/1 Running 1-(69m-ago) 5h26m
@@ -153,6 +155,11 @@ Here, we modified the 4th column (`-T4`) by replacing every space with
153155
a dash. If you need to work with `/` characters, you can also use any
154156
other separator, for instance: `-R '| |-|'`.
155157

158+
There's also an interactive mode, invoked with the option B<-I>, where
159+
you can interactively filter and select rows:
160+
161+
<img width="937" height="293" alt="interactive" src="https://github.com/user-attachments/assets/0d4d65e2-d156-43ed-8021-39047c7939ed" />
162+
156163

157164

158165
## Installation

cfg/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
const DefaultSeparator string = `(\s\s+|\t)`
31-
const Version string = "v1.5.4"
31+
const Version string = "v1.5.5"
3232
const MAXPARTS = 2
3333

3434
var DefaultConfigfile = os.Getenv("HOME") + "/.config/tablizer/config"
@@ -112,6 +112,8 @@ type Config struct {
112112

113113
// -r <file>
114114
InputFile string
115+
116+
OFS string
115117
}
116118

117119
// maps outputmode short flags to output mode, ie. -O => -o orgtbl

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ func Execute() {
132132
"Transpose the speficied columns (separated by ,)")
133133
rootCmd.PersistentFlags().BoolVarP(&conf.Interactive, "interactive", "I", false,
134134
"interactive mode (experimental)")
135+
rootCmd.PersistentFlags().StringVarP(&conf.OFS, "ofs", "", "",
136+
"Output field separator (' ' for ascii table, ',' for CSV)")
135137

136138
// sort options
137139
rootCmd.PersistentFlags().StringVarP(&conf.SortByColumn, "sort-by", "k", "",

cmd/tablizer.go

Lines changed: 79 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,46 @@ SYNOPSIS
99
tablizer [regex,...] [-r file] [flags]
1010
1111
Operational Flags:
12-
-c, --columns string Only show the speficied columns (separated by ,)
13-
-v, --invert-match select non-matching rows
14-
-n, --numbering Enable header numbering
15-
-N, --no-color Disable pattern highlighting
16-
-H, --no-headers Disable headers display
17-
-s, --separator string Custom field separator
18-
-k, --sort-by int|name Sort by column (default: 1)
19-
-z, --fuzzy Use fuzzy search [experimental]
20-
-F, --filter field[!]=reg Filter given field with regex, can be used multiple times
21-
-T, --transpose-columns string Transpose the speficied columns (separated by ,)
22-
-R, --regex-transposer /from/to/ Apply /search/replace/ regexp to fields given in -T
23-
-I, --interactive Interactively filter and select rows
12+
-c, --columns string Only show the speficied columns (separated by ,)
13+
-v, --invert-match select non-matching rows
14+
-n, --numbering Enable header numbering
15+
-N, --no-color Disable pattern highlighting
16+
-H, --no-headers Disable headers display
17+
-s, --separator <string> Custom field separator
18+
-k, --sort-by <int|name> Sort by column (default: 1)
19+
-z, --fuzzy Use fuzzy search [experimental]
20+
-F, --filter <field[!]=reg> Filter given field with regex, can be used multiple times
21+
-T, --transpose-columns string Transpose the speficied columns (separated by ,)
22+
-R, --regex-transposer </from/to/> Apply /search/replace/ regexp to fields given in -T
23+
-I, --interactive Interactively filter and select rows
2424
2525
Output Flags (mutually exclusive):
26-
-X, --extended Enable extended output
27-
-M, --markdown Enable markdown table output
28-
-O, --orgtbl Enable org-mode table output
29-
-S, --shell Enable shell evaluable output
30-
-Y, --yaml Enable yaml output
31-
-C, --csv Enable CSV output
32-
-A, --ascii Default output mode, ascii tabular
33-
-L, --hightlight-lines Use alternating background colors for tables
34-
-y, --yank-columns Yank specified columns (separated by ,) to clipboard,
35-
space separated
26+
-X, --extended Enable extended output
27+
-M, --markdown Enable markdown table output
28+
-O, --orgtbl Enable org-mode table output
29+
-S, --shell Enable shell evaluable output
30+
-Y, --yaml Enable yaml output
31+
-C, --csv Enable CSV output
32+
-A, --ascii Default output mode, ascii tabular
33+
-L, --hightlight-lines Use alternating background colors for tables
34+
-y, --yank-columns Yank specified columns (separated by ,) to clipboard,
35+
space separated
36+
--ofs <char> Output field separator, used by -A and -C.
3637
3738
Sort Mode Flags (mutually exclusive):
38-
-a, --sort-age sort according to age (duration) string
39-
-D, --sort-desc Sort in descending order (default: ascending)
40-
-i, --sort-numeric sort according to string numerical value
41-
-t, --sort-time sort according to time string
39+
-a, --sort-age sort according to age (duration) string
40+
-D, --sort-desc Sort in descending order (default: ascending)
41+
-i, --sort-numeric sort according to string numerical value
42+
-t, --sort-time sort according to time string
4243
4344
Other Flags:
44-
-r --read-file <file> Use <file> as input instead of STDIN
45-
--completion <shell> Generate the autocompletion script for <shell>
46-
-f, --config <file> Configuration file (default: ~/.config/tablizer/config)
47-
-d, --debug Enable debugging
48-
-h, --help help for tablizer
49-
-m, --man Display manual page
50-
-V, --version Print program version
45+
-r --read-file <file> Use <file> as input instead of STDIN
46+
--completion <shell> Generate the autocompletion script for <shell>
47+
-f, --config <file> Configuration file (default: ~/.config/tablizer/config)
48+
-d, --debug Enable debugging
49+
-h, --help help for tablizer
50+
-m, --man Display manual page
51+
-V, --version Print program version
5152
5253
DESCRIPTION
5354
Many programs generate tabular output. But sometimes you need to
@@ -75,16 +76,16 @@ DESCRIPTION
7576
kubectl get pods | tablizer
7677
7778
# read a file
78-
tablizer filename
79+
tablizer -r filename
7980
8081
# search for pattern in a file (works like grep)
81-
tablizer regex filename
82+
tablizer regex -r filename
8283
8384
# search for pattern in STDIN
8485
kubectl get pods | tablizer regex
8586
86-
The output looks like the original one but every header field will have
87-
a numer associated with it, e.g.:
87+
The output looks like the original one. You can add the option -n, then
88+
every header field will have a numer associated with it, e.g.:
8889
8990
NAME(1) READY(2) STATUS(3) RESTARTS(4) AGE(5)
9091
@@ -96,7 +97,13 @@ DESCRIPTION
9697
You can specify the numbers in any order but output will always follow
9798
the original order.
9899
99-
The numbering can be suppressed by using the -n option.
100+
However, you may also just use the header names instead of numbers, eg:
101+
102+
kubectl get pods | tablizer -cname,status
103+
104+
You can also use regular expressions with -c, eg:
105+
106+
kubectl get pods | tablizer -c '[ae]'
100107
101108
By default tablizer shows a header containing the names of each column.
102109
This can be disabled using the -H option. Be aware that this only
@@ -445,45 +452,46 @@ Usage:
445452
tablizer [regex,...] [-r file] [flags]
446453
447454
Operational Flags:
448-
-c, --columns string Only show the speficied columns (separated by ,)
449-
-v, --invert-match select non-matching rows
450-
-n, --numbering Enable header numbering
451-
-N, --no-color Disable pattern highlighting
452-
-H, --no-headers Disable headers display
453-
-s, --separator string Custom field separator
454-
-k, --sort-by int|name Sort by column (default: 1)
455-
-z, --fuzzy Use fuzzy search [experimental]
456-
-F, --filter field[!]=reg Filter given field with regex, can be used multiple times
457-
-T, --transpose-columns string Transpose the speficied columns (separated by ,)
458-
-R, --regex-transposer /from/to/ Apply /search/replace/ regexp to fields given in -T
459-
-I, --interactive Interactively filter and select rows
455+
-c, --columns string Only show the speficied columns (separated by ,)
456+
-v, --invert-match select non-matching rows
457+
-n, --numbering Enable header numbering
458+
-N, --no-color Disable pattern highlighting
459+
-H, --no-headers Disable headers display
460+
-s, --separator <string> Custom field separator
461+
-k, --sort-by <int|name> Sort by column (default: 1)
462+
-z, --fuzzy Use fuzzy search [experimental]
463+
-F, --filter <field[!]=reg> Filter given field with regex, can be used multiple times
464+
-T, --transpose-columns string Transpose the speficied columns (separated by ,)
465+
-R, --regex-transposer </from/to/> Apply /search/replace/ regexp to fields given in -T
466+
-I, --interactive Interactively filter and select rows
460467
461468
Output Flags (mutually exclusive):
462-
-X, --extended Enable extended output
463-
-M, --markdown Enable markdown table output
464-
-O, --orgtbl Enable org-mode table output
465-
-S, --shell Enable shell evaluable output
466-
-Y, --yaml Enable yaml output
467-
-C, --csv Enable CSV output
468-
-A, --ascii Default output mode, ascii tabular
469-
-L, --hightlight-lines Use alternating background colors for tables
470-
-y, --yank-columns Yank specified columns (separated by ,) to clipboard,
471-
space separated
469+
-X, --extended Enable extended output
470+
-M, --markdown Enable markdown table output
471+
-O, --orgtbl Enable org-mode table output
472+
-S, --shell Enable shell evaluable output
473+
-Y, --yaml Enable yaml output
474+
-C, --csv Enable CSV output
475+
-A, --ascii Default output mode, ascii tabular
476+
-L, --hightlight-lines Use alternating background colors for tables
477+
-y, --yank-columns Yank specified columns (separated by ,) to clipboard,
478+
space separated
479+
--ofs <char> Output field separator, used by -A and -C.
472480
473481
Sort Mode Flags (mutually exclusive):
474-
-a, --sort-age sort according to age (duration) string
475-
-D, --sort-desc Sort in descending order (default: ascending)
476-
-i, --sort-numeric sort according to string numerical value
477-
-t, --sort-time sort according to time string
482+
-a, --sort-age sort according to age (duration) string
483+
-D, --sort-desc Sort in descending order (default: ascending)
484+
-i, --sort-numeric sort according to string numerical value
485+
-t, --sort-time sort according to time string
478486
479487
Other Flags:
480-
-r --read-file <file> Use <file> as input instead of STDIN
481-
--completion <shell> Generate the autocompletion script for <shell>
482-
-f, --config <file> Configuration file (default: ~/.config/tablizer/config)
483-
-d, --debug Enable debugging
484-
-h, --help help for tablizer
485-
-m, --man Display manual page
486-
-V, --version Print program version
488+
-r --read-file <file> Use <file> as input instead of STDIN
489+
--completion <shell> Generate the autocompletion script for <shell>
490+
-f, --config <file> Configuration file (default: ~/.config/tablizer/config)
491+
-d, --debug Enable debugging
492+
-h, --help help for tablizer
493+
-m, --man Display manual page
494+
-V, --version Print program version
487495
488496
489497
`

0 commit comments

Comments
 (0)