1. 3

I often end up in situations where I’ve have tabular data that I need to format for presentation in a browser. I’d need a tool that can take tabular data in various formats - simple space or character delimited fields (as is common with UNIX CLI commands), CSV, and JSON and generate a HTML or markdown table with the data.

I have found https://www.tablesgenerator.com/html_tables which is a nice tool, but it is web based and doesn’t provide a way for me to batch input data into it. Does a CLI equivalent that does that exist?

  1. 3

    This is language specific, so may not be what you’re looking for? (Golang, ported from a Ruby lib)

    But it has HTML and Markdown output.

    https://github.com/apcera/termtables

    1. 1

      For those curious what I settled on, I ended up using the pandoc-placetable filter (http://hackage.haskell.org/package/pandoc-placetable) with Pandoc in a simple shell script that can read from STDIN or file, and outputs HTML. With this approach I could also produce Markdown tables from the CSVs as well.

      The script is available in my dotfiles: https://github.com/Stratus3D/dotfiles/blob/master/scripts/tools/csv2html

      1. 1

        I also just found this: http://jeroenjanssens.com/2013/09/19/seven-command-line-tools-for-data-science.html

        It shows a tool named csvlook, but I don’t think it can output Markdown or HTML tables.

        1. 1

          I don’t know it (and don’t endorse it, I’m very hesitant when it comes to unaudited npm packages) but after a quick search this seems like something you are looking for:

          https://www.npmjs.com/package/markdown-cli

          Edit: I think I misread your question. Nevermind! Maybe this is something that can help you:

          https://pypi.org/project/csv2md/

          It’s only csv unfortunately, but if you can find json and cli argument equivalents you can write your own simple shell script to incorporate all in one.

          1. 1

            It should be trivial to write a tool for this. Read from stdin, using your favourite language’s CSV parser, and print some HTML.

            There are a bunch of JSON to CSV tools, which you could perhaps use for JSON support. I would suspect that figuring out how to best use that will be harder than just modifying the program though.