Coder Social home page Coder Social logo

mdtable's Introduction

MDTable

Description

Reads from the stdin a space separated text, and prints on the stdout the markdown syntaxt of a table made by the text readed.

Usage

  • $ whatever | ./mdtable COLNAME_1 COLNAME_2 ... COLNAME_N Creates a table with the specified column names, starting by the output of whatever

  • $ whatever | ./mdtable -f Creates a table and uses the content of the first line of the output ofwhatever as the column names.

Make sure to give execution permission to the script so that it can be executed via ./mdtable.py

Example

Let's assume that you want to create a table of the current processes in your machine.
These are the first lines of output of the ps -aux command:

$ ps -aux | head
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0 120016  6188 ?        Ss   21:38   0:02 /sbin/init splash
root         2  0.0  0.0      0     0 ?        S    21:38   0:00 [kthreadd]
root         6  0.0  0.0      0     0 ?        S    21:38   0:00 [ksoftirqd/0]
root         7  0.4  0.0      0     0 ?        S    21:38   0:22 [rcu_sched]
root         8  0.0  0.0      0     0 ?        S    21:38   0:00 [rcu_bh]
root         9  0.0  0.0      0     0 ?        S    21:38   0:00 [migration/0]
root        10  0.0  0.0      0     0 ?        S<   21:38   0:00 [lru-add-drain]
root        11  0.0  0.0      0     0 ?        S    21:38   0:00 [watchdog/0]
root        12  0.0  0.0      0     0 ?        S    21:38   0:00 [cpuhp/0]

To create a table, just pipe the output to the mdtable.py script, and use -f flag to use the first line as the table headers.

$ ps -aux | head | ./mdtable -f
USER | PID | %CPU | %MEM | VSZ | RSS | TTY | STAT | START | TIME | COMMAND
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
root | 1 | 0.0 | 0.0 | 120016 | 6188 | ? | Ss | 21:38 | 0:02 | /sbin/init splash
root | 2 | 0.0 | 0.0 | 0 | 0 | ? | S | 21:38 | 0:00 | [kthreadd]
root | 6 | 0.0 | 0.0 | 0 | 0 | ? | S | 21:38 | 0:00 | [ksoftirqd/0]
root | 7 | 0.4 | 0.0 | 0 | 0 | ? | S | 21:38 | 0:24 | [rcu_sched]
root | 8 | 0.0 | 0.0 | 0 | 0 | ? | S | 21:38 | 0:00 | [rcu_bh]
root | 9 | 0.0 | 0.0 | 0 | 0 | ? | S | 21:38 | 0:00 | [migration/0]
root | 10 | 0.0 | 0.0 | 0 | 0 | ? | S< | 21:38 | 0:00 | [lru-add-drain]
root | 11 | 0.0 | 0.0 | 0 | 0 | ? | S | 21:38 | 0:00 | [watchdog/0]
root | 12 | 0.0 | 0.0 | 0 | 0 | ? | S | 21:38 | 0:00 | [cpuhp/0]

Now you can redirect this output to a markdown file and create an HTML from it that will result in something like this table below.

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 120016 6188 ? Ss 21:38 0:02 /sbin/init splash
root 2 0.0 0.0 0 0 ? S 21:38 0:00 [kthreadd]
root 6 0.0 0.0 0 0 ? S 21:38 0:00 [ksoftirqd/0]
root 7 0.4 0.0 0 0 ? S 21:38 0:25 [rcu_sched]
root 8 0.0 0.0 0 0 ? S 21:38 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? S 21:38 0:00 [migration/0]
root 10 0.0 0.0 0 0 ? S< 21:38 0:00 [lru-add-drain]
root 11 0.0 0.0 0 0 ? S 21:38 0:00 [watchdog/0]
root 12 0.0 0.0 0 0 ? S 21:38 0:00 [cpuhp/0]

mdtable's People

Contributors

giogiglio avatar

Stargazers

Richard Metzler avatar  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.