A background process is writing to a log and I want to output all text from this log to the terminal, up until the word "Do".
I'm using this command:
tail -f service.log | sed '/Do/ q'
For some reason, this command will output the word "Do" and wait until the next line is written to the log before it quits.
To verify, I ran my command and then manually appended to the file using the following commands in another window:
echo A >> service.log
# outputs 'A' in the sed window
echo B >> service.log
# outputs 'B' in the sed window
echo C >> service.log
# outputs 'C' in the sed window
echo Do >> service.log
# outputs 'Do' in the sed window, but the tail and sed command is still running.
echo E >> service.log
# now the tail and sed command finishes.
sed seems to quit only after the next line is written to the file, not when it was outputted.
How do I make my sed command quit on the first output of the word 'Do'?