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
cat somefile | grep somepattern
and the correction was ..
grep somepattern somefile --> this essentially what you said is planted..one less invocation of calls.
:)
Posted May 23, 2020 19:53 UTC (Sat)
by Jandar (subscriber, #85683)
[Link] (5 responses)
<somefile grep somepattern >output
The position of redirection doesn't matter only the order if there are dependencies.
Posted May 23, 2020 20:32 UTC (Sat)
by Wol (subscriber, #4433)
[Link] (4 responses)
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,
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.
Posted May 24, 2020 13:50 UTC (Sun)
by mpr22 (subscriber, #60784)
[Link] (1 responses)
Posted May 24, 2020 17:12 UTC (Sun)
by madscientist (subscriber, #16861)
[Link]
This can be useful in scripting to avoid the complexity of stripping off the unwanted filename.
Posted May 24, 2020 14:02 UTC (Sun)
by Wol (subscriber, #4433)
[Link]
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,
Surprisingly relevant?
Surprisingly relevant?
Wol
???
Surprisingly relevant?
Surprisingly relevant?
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.
Surprisingly relevant?
Surprisingly relevant?
Wol