[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: text formatting tool that can produce output like ls(1)?



On Sat, 28 Aug 2010 09:14:01 +0800, Zhang Weiwu wrote:

> The output of "ls" is pretty good because:
> 
>    1. It calculate column width from widest columns. 2. It knows one
>    Chinese ideograph is two letters wide. 3. It aligns columns by
>    flexible space character instead of tab
> 
> Is there a text formatting command that formats text like "ls" while
> take user supplied input?

You didn't provide a test case so here is mine:

$ perl -e 'foreach $ii (1..9){ foreach $jj (1..$ii) {print $ii; }; print 
"\t$ii\n"; } ' | tee /tmp/f1
1	1
22	2
333	3
4444	4
55555	5
666666	6
7777777	7
88888888	8
999999999	9

$ cat /tmp/f1 | column -t
1          1
22         2
333        3
4444       4
55555      5
666666     6
7777777    7
88888888   8
999999999  9

I also tried Chinese and it seems to be fine. Don't know if the following 
will come up as expected after post...

echo "媒体称香港青年系被警方大锤重创 x" >> /tmp/f1

$ cat /tmp/f1 | column -t
1                               1
22                              2
333                             3
4444                            4
55555                           5
666666                          6
7777777                         7
88888888                        8
999999999                       9
媒体称香港青年系被警方大锤重创  x

-- 
Tong (remove underscore(s) to reply)
  http://xpt.sourceforge.net/techdocs/
  http://xpt.sourceforge.net/tools/


Reply to: