I want to send a program from the last lines of a text file using tail as stdin.
First, I echo the program with some input that will be the same every time, and then send the tail input from the input file, which must first be processed through sed. Below is the command line that I expect to work. But when the program runs, it receives only the echo input, not the tail input.
(echo "new" && tail -f ~/inputfile 2> /dev/null | sed -n -r 'some regex' && cat) | ./program
However, it works as expected, printing everything to the terminal:
echo "new" && tail -f ~/inputfile 2> /dev/null | sed -n -r 'some regex' && cat
So, I tried with a different type of output, and again, when the text of the echo message is posted, the tail text is not displayed anywhere:
(echo "new" && tail -f ~/inputfile 2> /dev/null | sed -n -r 'some regex') | tee out.txt
This made me think that this is a buffering problem, but I tried the program unbufferand all the other recommendations here ( https://superuser.com/questions/59497/writing-tail-f-output-to-another-file ) without any either results. Where does the tail exit and how can I get it to enter my program as expected?
source
share