A command line tool to select columns from a table-shaped input, where columns are separated by multiple whitespaces (or a delimiter of your choice). Supports filtering and formatting.
Run table without any arguments to see available options.
Quick example:
-hwill treat the first line as the header and allow selecting the columns by name-sto choose which columns to output
docker images
#REPOSITORY TAG IMAGE ID CREATED SIZE
#bitnami/kafka 3.2 b7add9628c8e 4 weeks ago 657MB
#bitnami/zookeeper 3.8 000e247c0e4c 4 weeks ago 477MB
#openjdk 11.0 23d35e2be72f 7 weeks ago 650MB
docker images | table -h -s "TAG,IMAGE ID"
#output:
#3.2
#b7add9628c8e
#3.8
#000e247c0e4c
#11.0
#23d35e2be72f- regular select:
-s/--select. select the columns by name (if--headerflag is on) or by the index of the column. - excluding select:
-S/--exclude-selectselects all the columns except the requested. - projection:
-p/--projectallows to form an output string with placeholders for the requested columns. for example:
docker images | table -h -p "the image {REPOSITORY} is of size {SIZE}"will output
#the image bitnami/kafka is of size 657MB
#the image bitnami/zookeeper is of size 477MB
#the image openjdk is of size 650MB"You can filter only the rows you care about with -f/--filter. The filter works by searching if the cell includes the searched substring.
docker images:
#REPOSITORY TAG IMAGE ID CREATED SIZE
#bitnami/kafka 3.2 b7add9628c8e 4 weeks ago 657MB
#bitnami/zookeeper 3.8 000e247c0e4c 4 weeks ago 477MB
#openjdk 11.0 23d35e2be72f 7 weeks ago 650MB
docker images | table -h -s "TAG,IMAGE ID" -f "REPOSITORY=bitnami"
#output:
#3.2
#b7add9628c8e
#3.8
#000e247c0e4cTo split the columns by a different delimiter, such as dashes (-), you can use -d/--delimiter flag to choose a different character than whitespace.
In the following example the whitespaces has been replaced by dashes we declare dash to be the delimiter:
docker images
#REPOSITORY----------TAG----IMAGE ID-------CREATED-------SIZE
#bitnami/kafka-------3.2----b7add9628c8e---4 weeks ago---657MB
#bitnami/zookeeper---3.8----000e247c0e4c---4 weeks ago---477MB
#openjdk-------------11.0---23d35e2be72f---7 weeks ago---650MB
docker images | table -h -s "TAG,IMAGE ID" -d -
#output:
#3.2
#b7add9628c8e
#3.8
#000e247c0e4cTo change the amount of times the delimiter has to show up consecutively to split the columns, you can use the -r/--delimiter-repeats flag.
The following example shows a table input that is separated by a single tab (\t), so we will declare the delimiter to be the tab symbol, and the repetitions to be 1:
cat example.tsv
#CONST 123456 12.45
cat example.tsv | table -s 1 -d $'\t' -r 1
#output:
#123456Note on special character escaping: to properly pass special characters like tab (\t) or new line (\n), it needs to be interpreted by the shell like so: $'\t'.
table doesn't handle properly a specific case:
Right-justified column headers, for example notice the TIME column:
ps -ef
# UID PID PPID C STIME TTY TIME CMD
# 0 1 0 0 9Mar23 ?? 336:12.65 /sbin/launchd
# 0 323 1 0 9Mar23 ?? 43:20.14 /usr/libexec/logdThis case would not catch the width of the TIME column properly
While table can work with a JVM because it's written in Scala, it's intended to be a fast CLI tool, so it should be compiled to a native binary.
The build requires Clang/LLVM installed for Scala Native compilation. You can use SDKMAN to install JVM-related dependencies
- Scala-CLI or using SDKMAN:
sdk install scalacli - Clang/LLVM - see Scala Native's instructions
From the root directory
scala-cli --power package --native . -S 3.4.1 -o tablewill create an executable named table
scala-cli test . --native