Git Product home page Git Product logo

table's Introduction

Table

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:

  • -h will treat the first line as the header and allow selecting the columns by name
  • -s to 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

Selecting

  1. regular select: -s/--select. select the columns by name (if --header flag is on) or by the index of the column.
  2. excluding select: -S/--exclude-select selects all the columns except the requested.
  3. projection: -p/--project allows 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"

Filtering

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
#000e247c0e4c

Custom delimiter

To 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
#000e247c0e4c

custom repetitions of the delimiter

To 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:
#123456

Note 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'.

Limitations

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/logd

This case would not catch the width of the TIME column properly


Build

Setup

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

requirements:

  1. Scala-CLI or using SDKMAN: sdk install scalacli
  2. Clang/LLVM - see Scala Native's instructions

Compile and packge an executable

From the root directory

scala-cli --power package --native .  -S 3.4.1 -o table

will create an executable named table

Test

scala-cli test . --native

table's People

Contributors

leonbur avatar

Stargazers

Avi Haimov avatar Omri Chen avatar talkot avatar Ben Wattelman avatar Natan Silnitsky avatar Asaf Jaffi avatar Dima avatar Eugene Krapivin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.