Sample Header Ad - 728x90

Pipe output from process substitution to variable

2 votes
3 answers
1566 views
I have very complicated set of commands:
command | ... | ... | tee >(grep -c '[^3]$') >(grep -c '[^35]$') 1>/dev/null
I don't want to have a temporary file to save up output, as it is pretty huge. I tried doing >(grep -c '[^3]$' | read variable) and >(grep -c '[^3]$' | read variable2) but I guess bit doesn't work because of process substitution's sub-shell invocation. What can I do to pipe output directly to multiple variables? Is it even possible? Right now I have this workaround:
var=$(command ... | ... | ... | tee >(grep -c '[^3]$') >(grep -c '[^35]$') 1>/dev/null)
var1=$(tail -1 <<< $var)
var2=$(head -1 <<< $var)
but I think it is clumsy and doesn't look nice. I am aware I can grep into another file but I don't like it either. Thanks in advance.
Asked by Fedja (125 rep)
May 13, 2021, 02:23 PM
Last activity: Jan 14, 2025, 12:03 AM