grepoutputtee

Why does grep only print after quitting?


I want to save the terminal output of a specific program to a file. But I need to do two special things: a) I want to output to be duplicated (not redirected) to the file b) I want to run grep on the output to save only specific lines.

The command I've come up with is

cd ~/MagicMirror && DISPLAY=:0 npm start | tee >( grep 'BACKGROUNDSLIDESHOW: reading path' >> bgss-log.txt )

which seems to work okay. But it only seems to save the output to the file after I quit the program (the output in the terminal continues to show in real time).

Is there something wrong with my syntax? Or is it something funny with this particular program (or maybe it's use of npm)?


Solution

  • grep buffers 4096 bytes by default; try

    grep --line-buffered