I would like to format text content that I am getting as a stdout stream using column, but I fail. For instance, using a single line, all works fine:
$ echo "1 12 123 1234 1 12 123 1234 " | column -t
1 12 123 1234 1 12 123 1234
.. however, if I try to simulate an “endless” stream:
$ while true; do echo "1 12 123 1234 1 12 123 1234 "; sleep 1; done | column -t
^C
… there is simply no response, until one exits with Ctrl-C.
(Note that the while thing is just meant to simulate reading an endless stream from a device, as in ‘cat /dev/ttyUSB0‘)
This leads me to believe that, even if column by default should accept standard input, it needs a “complete” and finished file (that is, with a determined file size) in order to work; and in the case of an “endless” stream, that is not the case – so it never outputs anything.
Any suggestion on how I could achieve column formatting in this context? EDIT: Doesn’t necesarily have to be the column program; anything else that formats text into columns would be fine (but I’m afraid, for instance awk also needs a complete file)…
Thanks in advance,
Cheers!
I, too, found column disappointing in its inability to stream, and sdaau’s code in its inability to measure my columns. So here’s a fix for both those problems. Maybe not terribly efficient, but it’s just for debugging, anyway. I have it in my ~/bin folder as
pcol(be sure to chmod +x it):