[Tfug] rereading stdin

Claude Rubinson rubinson at u.arizona.edu
Fri Feb 17 19:29:08 MST 2006


I'm wondering how people handle situations in which they need to step
through stdin more than once.  As an example, lets say that I want to
compute some deviation statistics: x - mean(x).  The formula requires
that I step through the input twice, once to compute mean(x) and once
to compute x - mean(x) for every x.

If I'm working in a higher-level language (such as Python), this isn't
an issue as I'll have already read the input into an object of some
sort.  Where it rears its head is when I'm working in shell (as is my
preference).  I can read the input into variables (or, more likely,
arrays) or write it first to a temp file (possibly using tee).  I tend
to prefer the second solution (with tee) but both feel kludgey to me.

Thoughts?

Claude


More information about the tfug mailing list