tablefmt: an attempt at a text filter.

Revealed by sykora within programming on October 21st, 2008

While I was just generally looking through vim-related links at digg and the like, I came across a site with a number of text-related tools that can be used as text filters in vim (and elsewhere, of course). A filter is a program which takes lines of text, performs some operation and returns more lines of text, which are substituted in place of the original text. One of these which I could find a really good use for, was a filter which converted misaligned table data into an aligned table. However, the link for this program was broken, and I never found it anywhere.

Because of this, and the fact that I had nothing better to do, I wrote one myself.

Enter tablefmt, a simple text filter which does exactly what I said in the last paragraph. It’s written in python, and till date supports a few features such as input delimiters and output delimiters. More is planned, though.

Here is an example of tablefmt in action :

(tablefmt:master)-
(%:!1136)- cat > tablefmt_test.txt
January 50 100 1000
March 20 10 300
July 100 20 5000
November 3000 200 10000
(sykora@localhost)-(21:55:07)-(tablefmt:master)-
(%:!1137)- python tablefmt.py < tablefmt_test.txt
 January   50 100  1000
   March   20  10   300
    July  100  20  5000
November 3000 200 10000
(sykora@localhost)-(21:55:25)-(tablefmt:master)-
(%:!1138)-

The code is available on my github site, namely http://github.com/sykora/tablefmt/, but only the .py file is required.

Try it out, and tell me if you like it :)

Tags: , , , , , , ,

Leave a Reply

Powered by Wordpress, valid XHTML and CSS. Original theme by Themelab, modifications by me.
Gatekeeper