help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] How to merge stdout and stderr yet distinguish what is f


From: Andy Chu
Subject: Re: [Help-bash] How to merge stdout and stderr yet distinguish what is from stdout and what is from stderr?
Date: Sun, 4 Feb 2018 14:33:17 -0800

On Sun, Feb 4, 2018 at 1:34 PM, Peng Yu <address@hidden> wrote:

> Hi,
>
> `cmd 2>&1` can be used to merge stdout stderr into one stream. But the
> content from stdout and stderr are not distinguishable anymore.
>
> Is there a way to not only merge stdout and stderr but also prepend
> each line from stdout with a prefix and prepend each line from stderr
> with a different prefix (e.g., 'o' and 'e' respectively) so that they
> are distinguishable (we assume that there will be no merged lines
> coming from both stdout and stderr)?
>


Joao just gave the same answer as I was typing it, but:

https://github.com/oilshell/blog-code/blob/master/stdout-stderr/demo.sh

I don't like process substitution that much, because the syntax looks odd.
For me it helps to think of it as

prog > $stdin(awk ... )  2> $stdin(awk ...)   # imaginary syntax

The $ makes it clearer that it expands to a word like /dev/fd/64.  >() is
confusing especially when preceded by the redirect operators!


$ ./demo.sh prog
1
2
3
4
5
6
7
8
9

$ ./demo.sh filter
o 1
o 2
o 3
e 4
e 5
e 6
o 7
o 8
o 9


Andy

(reply to all this time)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]