[colug-432] Nice Plain Text Columns and Avoiding NIH: expand: not

Rob Funk rfunk at funknet.net
Mon Aug 29 12:39:20 EDT 2011


On Monday, August 29, 2011 12:14:33 PM Stephen Potter wrote:
> On 8/8/2011 11:29 AM, Richard Holbert wrote:
> > Seth,
> > Please try the following to see if it also works as expected:
> > 
> > cat foo.txt | column -t -s $'\t'
> 
> Why the extraneous "cat" in there?  Why not just
> 
> column -t -s $'\t' foo.txt

Or even:
column -t -s $'\t' < foo.txt

That's a longstanding argument in the Unix world.....

While all work, I like the first version because it explicitly separates the 
source from the filter. The second version muddles the filter parameters 
together with the source parameter. The third version has more separation, but 
still gets confusing, or at least less than straightforward, if you start 
adding more filters.

A lot of times I'll write scripts that look something like:
cat foo |\
  filter --somehow |\
  another-filter --some-other-way |\
  more-filtering --with-more-options

And it's nice to be able to easily vary the source (e.g. cat, echo, curl) 
separately from the filters, with a direct pipeline from beginning to end.

At one time there was a good machine-performance argument for not running the 
extra "cat" command unnecessarily. I'm pretty sure that even my router and my 
phone wouldn't notice it at this point. Clarity should be a top priority.

On the other hand, the second version is shorter to type, so if you're just 
typing at the command line rather than writing a script, that's the way you 
want to go.  :-)


More information about the colug-432 mailing list