From: Chad on
On Jun 2, 9:11 pm, Bit Twister <BitTwis...(a)mouse-potato.com> wrote:
> On Wed, 2 Jun 2010 19:26:37 -0700 (PDT), Chad wrote:
> > What's the difference between
>
> > % w | wc -l
> >       33
>
> > versus something like..
>
> > % wc -l <(w)
> >       33 /tmp/zshx9eHyc
> > %
>
> /tmp/zshx9eHyc
>
> > I mean, they both give the same results. Is there any particular
> > advantage of using one over the other?
>
> Both seem inefficient to me. I would do something like
>
> line_count=$(wc -l < /some/file)


How do you figure the following is more efficient.

line_count=$(wc -l < /some/file)
From: Barry Margolin on
In article
<7ee000c8-e076-4dde-b686-2ac66b69504b(a)v29g2000prb.googlegroups.com>,
Chad <cdalten(a)gmail.com> wrote:

> On Jun 2, 7:54�pm, Barry Margolin <bar...(a)alum.mit.edu> wrote:
> > In article
> > <b0e62205-3ba2-491c-991b-d51d15ca0...(a)s6g2000prf.googlegroups.com>,
> >
> > �Chad <cdal...(a)gmail.com> wrote:
> > > What's the difference between
> >
> > > % w | wc -l
> > > � � � 33
> >
> > > versus something like..
> >
> > > % wc -l <(w)
> > > � � � 33 /tmp/zshx9eHyc
> > > %
> >
> > > I mean, they both give the same results. Is there any particular
> > > advantage of using one over the other?
> >
> > As you can see, they don't actually give the same results. �In one case,
> > wc is given a filename parameter, so it displays the filename in its
> > output; in the other case, it's reading from stdin, so there's no
> > filename to display.
> >
> > <(...) is generally used in situations where ordinary piping won't fork. �
> > For instance, I've used it with programs that take multiple file
> > arguments and process them together, rather than sequentially, e.g.
> >
> > diff <(...) <(...)
> >
>
> What are some situations where ordinary piping won't fork?

Oops, I meant "won't work". What a crazy typo, it still makes sense in
context, so the error isn't immediately obvious, but what it states is
definitely wrong.

--
Barry Margolin, barmar(a)alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Barry Margolin on
In article <slrni0eaqs.8rc.BitTwister(a)cooker.home.test>,
Bit Twister <BitTwister(a)mouse-potato.com> wrote:

> On Wed, 2 Jun 2010 19:26:37 -0700 (PDT), Chad wrote:
> > What's the difference between
> >
> > % w | wc -l
> > 33
> >
> > versus something like..
> >
> > % wc -l <(w)
> > 33 /tmp/zshx9eHyc
> > %
> >
>
> /tmp/zshx9eHyc
>
> > I mean, they both give the same results. Is there any particular
> > advantage of using one over the other?
>
> Both seem inefficient to me. I would do something like
>
> line_count=$(wc -l < /some/file)

Don't you first have to get the output of "w" into /some/file? Isn't
that less efficient, since it has to write to disk? Also, it prevents w
and wc from being run in parallel, you can't start wc until after w
executes.

--
Barry Margolin, barmar(a)alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Bit Twister on
On Thu, 03 Jun 2010 22:07:44 -0400, Barry Margolin wrote:

> Don't you first have to get the output of "w" into /some/file? Isn't
> that less efficient, since it has to write to disk?

True, I just saw the | wc -l and without checking what was going on
showed you can use wc < whatever without using the pipe operator.

My Bad. Sorry.
From: Ben Finney on
Barry Margolin <barmar(a)alum.mit.edu> writes:

> Chad <cdalten(a)gmail.com> wrote:
> > What are some situations where ordinary piping won't fork?
>
> Oops, I meant "won't work". What a crazy typo, it still makes sense in
> context, so the error isn't immediately obvious, but what it states is
> definitely wrong.

Freud would be proud :-)

--
\ “Natural catastrophes are rare, but they come often enough. We |
`\ need not force the hand of nature.” —Carl Sagan, _Cosmos_, 1980 |
_o__) |
Ben Finney