3 ms·
The problem - you have file, you want to do one thing for lines matching REGEX and other thing for lines not-matching REGEX. How to do it without iterating the
by ajuc 12y ago
The problem - you have file, you want to do one thing for lines matching REGEX and other thing for lines not-matching REGEX.
How to do it without iterating the file 2 times? You can do while of course, but it defeats the reason to use shell.
I would love to have two-way grep that writes matching lines to stdout and nonmatching to stderr. I wonder if grep maintainers would accept new option for grep "--two-way".
- jiffytick 12y agoawk can write to stderr.
- ticviking 12y agoWhich is for errors.
- barrkel 12y agoWrite to more than one fifo from awk. If you're composing a dag rather than a pipeline, fifos are one way to go. Personally though, I'd output to temporary files. The extra cost in disk usage and lack of pipelining is made up for by the easier debugging, and most shell pipelines aren't so slow that they need that level of optimization.