Re: [mu TECH] wc : faster, more gnarly

From: Alfie Costa (
Date: Wed Mar 22 2000 - 07:33:35 CET

On 21 Mar 00, at 11:52, Michele Andreoli <> wrote:

> A pure ash solution is:
> ls -Uo * |
> while read x1 x2 x3 x4
> do
> echo $x4
> done
> This save a further fork calling awk.

Not sure awk is a bottleneck right there, as it's only called once per run. The
real awk slowdown is in the output in ShowLine(), (called once per filename,
plus one), but it'd be sad to lose it if it meant giving up the formatted
columnar spacing.

Anyhow, I tried the code above, and it works, but it needs three changes, which
are commented here for anybody who's interested...

[ "$c" ] && charlist=`ls -Uo "$@" |
while read x1 x2 x3 x4 x5 # x5 needed
        echo -n $x4" " # '-n' needed, as well as a space...

'read' turns out to be tricky. If it only gets one variable, like 'read x', it
puts the whole line in there, that is, in $x. If it gets more than one
variable, it puts parameter #1 of the line read in the first variable,
parameter #2 in the second, and so on, up to the penultimate variable. The
last variable gets everything that remains on the line.

If that one line read happened to be:

drwxrwxr-x igor monsters 897 Nov 11 1999 foo2

...then 'read x1 x2 x3 x4' would result in:
x4="897 Nov 11 1999 foo2"

So of course, the $x5 is to eat up that last 'Nov 11 1999 foo2' stuff.

I'll e-mail the further altered 'crudewc', with the above code. Alas, it is
again back to using the 'dummyoption -- shift' business, as the 'set -' syntax
kills any previous 'set' flags, like 'set -x' for debugging.

To unsubscribe, e-mail:
For additional commands, e-mail:

This archive was generated by hypermail 2.1.6 : Sat Feb 08 2003 - 15:27:13 CET