On 24May2020 19:28, David Mertz <[email protected]> wrote:
On Sun, May 24, 2020 at 6:56 PM Steven D'Aprano <[email protected]> wrote:

> I use bash a lot, and writing something like this is common:
> cat data | sort | cut -d; -f6 | grep ^foo | sort -r | uniq -c

And today's "Useless Use Of cat Award" goes to... :-)

    sort data | ...

(What is it specifically about cat that is so attractive? I almost
certainly would have done exactly what you did, even knowing that sort
will take a file argument.)


This is probably going afield since it is a bash thing, not a Python
thing.  But I can actually answer this quite specifically.

When I write a pipeline like that, I usually do not do it in one pass.  I
write a couple of the stages, look at what I have, and then add some more
stages until I get it right.  Many of the commands in the pipeline can take
a file argument (not just sort, also cut, also grep, also uniq...
everything I used in the example).

People forget that redirections may appear anywhere rather than just at the end of the command:

   <data sort | cut | ... >output

But I take your point on incremental build-the-pipeline, I do that a lot.

Cheers,
Cameron Simpson <[email protected]>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/26XKIQ6VS4ALVT52PL4ON33SUNNX33WR/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to