On 2010年08月26日 11:02, Zhang Weiwu wrote: > I always want a tool that: > > * Check the whole data file, for each column, find the widest cell. > * expand the data file, use widest cell for each column. > * it should know one ideograph counts two characters wide. > With awk it also can be done, in fact one line:
$ printf "ab\tcde\nf\tgh\n" > /tmp/test.tsv $ awk -F $'\t' 'FILENAME != "-" { for (i=1; i<=NF; i++) {max[i] = (length($i) > max[i] ? length($i) : max[i]); }} FILENAME == "-" {for (i=1; i<=NF; i++) { printf("%-" max[i] "s ", $i);;} print "";}' /tmp/test.tsv - < /tmp/test.tsv ab cde f gh But my awk one-liner have the fault that is the Chinese ideograph is counted as one character, not as two character-wide. I don't know a way to fix that yet. -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/4c77e3ab.6090...@realss.com