Prev: Free Live Voice and Video Chat!Connect with Over 4 Million Members download now
Next: Simple hack to get $500 to your home.
From: Chad on 2 Jun 2010 22:26 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?
From: Barry Margolin on 2 Jun 2010 22:54 In article <b0e62205-3ba2-491c-991b-d51d15ca0a6e(a)s6g2000prf.googlegroups.com>, Chad <cdalten(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 <(...) <(...) -- 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: Chad on 2 Jun 2010 23:01 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?
From: Bit Twister on 3 Jun 2010 00:11 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)
From: Ben Bacarisse on 3 Jun 2010 09:09
Bit Twister <BitTwister(a)mouse-potato.com> writes: > 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) Is that a reasonable alternative? Both the OP's examples are "inefficient" presumably because they run two progresses rather than one; but that is because the wc command runs on the output of w rather than a file, no? If the OP is counting users, w -h is better. I'd be tempted to write: W=$(who -q) W=${W#*users=} but I don't know how portable the output from who -q is. -- Ben. |