1

This works:

tail -f debug.log | grep RFC

...but this does not:

tail -f debug.log | grep RFC > file.log

Can you help me figure out why?

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56

1 Answers1

1

Your problem

Your output is buffered and redirected to file.log only when tail and grep are done. That's because, by default, grep keeps its output buffered when it does not output to a terminal (in your case, the output goes the file file.log).

tail used with its -f option never stops sending output to grep, which never sent its output in the redirection since grep waits for tail to stop sending input before writing its buffer to your output file.

Solution

To redirect your command's output to a file, you can use grep's --line-buffered option:

tail -f debug.log | grep --line-buffered RFC > file.log

Source

From grep's man page:

 --line-buffered
         Force output to be line buffered.  By default, output is line
         buffered when standard output is a terminal and block buffered
         otherwise.
Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56