Redirecting tail output into a program
<p>I want to send a program the most recent lines from a text file using tail as stdin.</p>

<p>First, I echo to the program some input that will be the same every time, then send in tail input from an inputfile which should first be processed through sed. The following is the command line that I expect to work. But when the program runs it only receives the echo input, not the tail input.</p>

<pre><code>(echo "new" &amp;&amp; tail -f ~/inputfile 2&gt; /dev/null | sed -n -r 'some regex' &amp;&amp; cat) | ./program
</code></pre>

<p>However, the following works exactly as expected, printing everything out to the terminal:</p>

<pre><code>echo "new" &amp;&amp; tail -f ~/inputfile 2&gt; /dev/null | sed -n -r 'some regex' &amp;&amp; cat
</code></pre>

<p>So I tried with another type of output, and again while the echoed text posted, the tail text does not appear anywhere:</p>

<pre><code>(echo "new"  &amp;&amp; tail -f ~/inputfile 2&gt; /dev/null | sed -n -r 'some regex') | tee out.txt 
</code></pre>

<p>This made me think it is a problem with buffering, but I tried the <code>unbuffer</code> program and all other advice here (<a href="https://superuser.com/questions/59497/writing-tail-f-output-to-another-file">https://superuser.com/questions/59497/writing-tail-f-output-to-another-file</a>) without results. Where is the tail output going and how can I get it to go into my program as expected?</p>