[ale] xargs processes as input arrives?

Richard Bronosky Richard at Bronosky.com
Fri Apr 17 14:20:17 EDT 2009


I would not trust anyone's experience on this.  Different versions of
xargs could behave differently. I suggest creating a controlled test
in a temp dir one the system in question. Here is my test:
~/ # cd $(mktemp -d); for f in a b c; do date>$f; sleep 1; done; ls
-rt|xargs grep Apr
a:Fri Apr 17 14:11:37 EDT 2009
b:Fri Apr 17 14:11:38 EDT 2009
c:Fri Apr 17 14:11:39 EDT 2009
/tmp/tmp.yk0aie9Nur #

I think the effect you are seeing is how grep handles multiple file
arguments. To be sure that xargs is the one choosing the order, tell
it max-args 1. Like so:
/tmp/tmp.yk0aie9Nur # for f in a b c; do date>$f; sleep 1; done; ls
-rt|xargs -n 1 grep Apr
Fri Apr 17 14:15:01 EDT 2009
Fri Apr 17 14:15:02 EDT 2009
Fri Apr 17 14:15:03 EDT 2009
/tmp/tmp.yk0aie9Nur #

Either way I get the order expected. But, don't trust my test results.
The man xargs page refers to POSIX standards changes from 1997 and
2004, blah, blah. You need to know what yours does and no one elses.

.!# RichardBronosky #!.



On Fri, Apr 17, 2009 at 1:53 PM, Jeff Lightner <jlightner at water.com> wrote:
> I’ve always assumed xargs processed each item as it arrived but saw
> something today that made me think perhaps this isn’t the case.
>
>
>
> In essence I’m doing an “ls –tr log.* |xargs grep –hA 30 sometext”
>
>
>
> Files are log, log.1, log.2 … log.10 where log is the newest and log.10 is
> the oldest.
>
>
>
> My subsequent processing relies on the information from log.10 appearing
> first then log.9 then log.8 … log.
>
>
>
> What I saw today made it look as if it somehow grabbed log.10 at the end
> instead of the beginning.
>
>
>
> Apparently they were doing some tweaking of logs today so it’s possible what
> I saw was a result of them moving something.
>
>
>
> I’d just like confirmation that xargs does in fact process things (and
> display it) in the order of what is piped into it rather than buffering it
> all and deciding on its own order.
>
>
>
> Nothing in the man page seems to directly answer question about order.
>
>
> Please consider our environment before printing this e-mail or attachments.
> ----------------------------------
> CONFIDENTIALITY NOTICE: This e-mail may contain privileged or confidential
> information and is for the sole use of the intended recipient(s). If you are
> not the intended recipient, any disclosure, copying, distribution, or use of
> the contents of this information is prohibited and may be unlawful. If you
> have received this electronic transmission in error, please reply
> immediately to the sender that you have received the message in error, and
> delete it. Thank you.
> ----------------------------------
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
>
>



More information about the Ale mailing list