Reads from the stdin a space separated text, and prints on the stdout the markdown syntaxt of a table made by the text readed.
-
$ whatever | ./mdtable COLNAME_1 COLNAME_2 ... COLNAME_N
Creates a table with the specified column names, starting by the output ofwhatever
-
$ 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
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] |