Re: [Help-bash] How to merge stdout and stderr yet distinguish what is f
From:
Russell Lewis
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 22:01:47 -0700
Dennis, I skimmed the link you posted. You're correct that, when you use
process substitution, the 'tee' programs run in the background, and it's
hard to wait on them.
However, I found a hackish solution for that: a trailing 'cat' :
cmd > >(tee logfile) | cat
Basically, the 'cat' is reading from the stdout of the things before the
pipe - which includes the stdout of the 'tee'. So 'cat' won't terminate
until it has read everything from 'tee', and copied it to screen. And bash
will wait for 'cat' to terminate.
Russ
On Sun, Feb 4, 2018 at 3:34 PM, Dennis Williamson <
address@hidden> wrote:
> On Feb 4, 2018 3: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)?
>
> Maybe this can be done through an external program, but I am not sure
> how to implement, especially, if I want the order of the lines
> combined from both streams unchanged whether there are prefixes or
> not.
>
> Does anybody know a solution to this problem? Thanks.
>
> --
> Regards,
> Peng
>
>
> Please see https://mywiki.wooledge.org/BashFAQ/106
>