|
|
Subscribe / Log in / New account

Surprisingly relevant?

Surprisingly relevant?

Posted May 23, 2020 12:22 UTC (Sat) by unixbhaskar (guest, #44758)
In reply to: Surprisingly relevant? by Wol
Parent article: The state of the AWK

Agreed! Many many moons ago someone wise corrects me the correct way, I was doing like everyone else in wild this:

cat somefile | grep somepattern

and the correction was ..

grep somepattern somefile --> this essentially what you said is planted..one less invocation of calls.

:)


to post comments

Surprisingly relevant?

Posted May 23, 2020 19:53 UTC (Sat) by Jandar (subscriber, #85683) [Link] (5 responses)

If you wish to retain the idea of a pipe: input -> command -> output, you could write

<somefile grep somepattern >output

The position of redirection doesn't matter only the order if there are dependencies.

Surprisingly relevant?

Posted May 23, 2020 20:32 UTC (Sat) by Wol (subscriber, #4433) [Link] (4 responses)

You're missing the point - the point is to GET RID of pipes.

Every extra pipe is an extra trip round the setup/teardown busywork loop - which if you pre-allocate memory could actually be a big problem even if you think you have plenty.

Cheers,
Wol

Surprisingly relevant?

Posted May 24, 2020 13:18 UTC (Sun) by madscientist (subscriber, #16861) [Link] (3 responses)

???

There are no pipes in Jandar's suggested alternative.

This feels more like StackOverflow than LWN, but the issue is that grep foo somefile gives different output than cat somefile | grep foo and if you want the latter behavior while still avoiding UUoC, you should be using grep foo < somefile instead.

Surprisingly relevant?

Posted May 24, 2020 13:50 UTC (Sun) by mpr22 (subscriber, #60784) [Link] (1 responses)

In what way does the output of grep pattern singlefile.txt differ from the output of cat singlefile.txt | grep?

Surprisingly relevant?

Posted May 24, 2020 17:12 UTC (Sun) by madscientist (subscriber, #16861) [Link]

You're right, grep behaves the same; my bad! I was thinking of some other tools like wc which have different output when given a filename versus reading from stdin.

This can be useful in scripting to avoid the complexity of stripping off the unwanted filename.

Surprisingly relevant?

Posted May 24, 2020 14:02 UTC (Sun) by Wol (subscriber, #4433) [Link]

Umm...

On first thoughts my reaction was "aren't < and > just different syntaxes for pipes?".

My second thought now is that "no they aren't actually pipes, they're shell built-ins".

So yeah you're right. They're pretty much identical in effect (and concept), but different in implementation and impact on the system. There's more than one way to do it ... :-)

Cheers,
Wol


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds