I don't have much experience of using tee, so I hope this is not very basic.
After viewing one of the answers to this question I came across a strange beheviour with
In order for me to output the first line, and a found line, I can use this:
ps aux | tee >(head -n1) | grep syslog USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND syslog 806 0.0 0.0 34600 824 ? Sl Sep07 0:00 rsyslogd -c4
However, the first time I ran this (in zsh) the result was in the wrong order, the column headers were below the grep results (this did not happen again however), so I tried to swap the commands around:
ps aux | tee >(grep syslog) | head -n1 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
Only the first line is printed, and nothing else! Can I use tee to redirect to grep, or am I doing this in the wrong manner?
As I was typing this question, the second command actually worked once for me, I ran it again five times and then back to the one line result. Is this just my system? (I am running zsh within tmux).
Finally, why with the first command is "grep syslog" not shown as a result (there is only one result)?
For control here is the grep without the
ps aux | grep syslog syslog 806 0.0 0.0 34600 824 ? Sl Sep07 0:00 rsyslogd -c4 henry 2290 0.0 0.1 95220 3092 ? Ssl Sep07 3:12 /usr/bin/pulseaudio --start --log-target=syslog henry 15924 0.0 0.0 3128 824 pts/4 S+ 13:44 0:00 grep syslog
Update: It seems that head is causing the whole command to truncate (as indicated in the answer below) the below command is now returning the following:
ps aux | tee >(grep syslog) | head -n1 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND syslog 806