Re: Filter stdout and stderr Together
- From: Dan Stromberg <dstromberglists@xxxxxxxxx>
- Date: Thu, 14 Aug 2008 17:36:40 GMT
On Thu, 14 Aug 2008 10:07:57 -0700, Scott Wegner wrote:
Hi All,
I would like to write a script that filters lines from both stdout and
stderr, and output the lines in the same order as they were originally
submitted. I've tried a few times using some complex stream redirection
and "grep -v ...", although I can't seem to get the results I want *in
order*. Has anybody done this before? Essentially I want a shell
script with the following syntax:
myscript command params
where myscript is the script I'm writing. command and params is what
should be executed. Output from the command should come on stdout and
stderr as expected, but with particular lines filtered out. My first
attempt was something along the lines of:
#!/usr/bin/env bash
MYFILTER="uninteresting output"
((($@) | grep -v "$MYFILTER") 3>&1 1>&2 2>&3 | grep -v "$MYFILTER") 2>&1
1>&3 3>&2
However, this was outputting text in the wrong order. Anybody know what
I'm doing wrong?
Scott
If you don't mind losing the distinction between stdout and stderr,
easiest is probably to:
eval "$@" 2>&1 | grep -v "$MYFILTER"
If you do mind losing the distinction, it gets harder. In that case, you
might end up writing in more of a general purpose language like python
(using the powerful subprocess module) or similar, and reading from the
two file descriptors in a select loop or with two threads.
.
- Follow-Ups:
- Re: Filter stdout and stderr Together
- From: Scott Wegner
- Re: Filter stdout and stderr Together
- References:
- Filter stdout and stderr Together
- From: Scott Wegner
- Filter stdout and stderr Together
- Prev by Date: Similar to "$@" but doesn't expand to an empty string on no arguments?
- Next by Date: Re: Similar to "$@" but doesn't expand to an empty string on no arguments?
- Previous by thread: Filter stdout and stderr Together
- Next by thread: Re: Filter stdout and stderr Together
- Index(es):
Relevant Pages
|