1

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'?

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
rodentry
  • 268
  • 3
  • 12

1 Answers1

-1

Try with capital Q

sed '/Compiled/Q'

@rodentry, you're right. How about

sed 's/Do/\n/' | head -1

Or the solution must be sed only?

Pero
  • 1,371
  • 17
  • 18