2

All I wanted is to grep for specific lines in an ongoing log and re-direct it to some file..

tailf log | grep "some words"

Now, I want the above command output to get re-directed to some file in on-going basis....

I tried,

tailf log | grep "some words" >> file

But that doesn't seem to work. What am I missing?

1
  • what happen ? empty file ? file with jump line ? nothing ? tailf only access file when modify. are you sure your log is not empty ?
    – Kiwy
    Feb 13 '14 at 13:19
12

The issue is buffering.

Use the --line-buffered option to force grep to flush the buffer after every line:

tailf log | grep --line-buffered "some words" >> file
1
  • Worked like a charm.. I have a little further requirement.. I will try that myself and see how it goes.. Thank you so much..
    – Gokul
    Feb 13 '14 at 14:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.