Re: cat and pipelines, mostly (was Re: Delete all after a pattern)
On Tue 03 Sep 2019 at 09:49:45 (-0400), Greg Wooledge wrote:
> On Sat, Aug 31, 2019 at 06:49:38PM -0500, David Wright wrote:
> > Exactly; so
> > cat afile | some-filter …
> > is just the degenerate of the general case
> > cat somefiles* | some-filter …
> > where there happens to be only one filename matching somefiles*.
> > So if you start prototyping some complicated command line by typing
> > for example:
> >
> > cat some-directory/… |
> >
> > you don't have to think about whether said directory might contain a
> > single file or several, and instead just concentrate on the problem
> > in hand, after the pipe.
>
> For interactive use, this is fine. It would be pointless to spend 60
> seconds optimizing a one-time interactive command to make it run 60
> milliseconds faster.
>
> For scripts, however, one expects to run the script more than once, and
> one expects the script to have correct behavior.[1] So, a bit of
> effort spent writing it properly is well invested.
>
> [1] I speak hypothetically, of course. In real life, I expect every
> shell script I encounter to be complete shit. Most especially any
> script that's part of a commercial product.
I agree with all your sentiments. However, with the OP struggling with
basic sed scripting, I can't help wondering whether there's any point
in feeding them
(sed 's/config=.*$/config=/g' | tr -d '=') <~/test.txt >~/other_test.txt
i=~/test.txt; o=~/other_test.txt; (sed 's/config=.*$/config=/g' | tr -d '=') <${i} >${o}
and so on at this stage. Hopefully they will invest in reading your
web pages in time…
Cheers,
David.
Reply to: