Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Zelda, Anthon, slm, Timo, peterph Feb 13 at 16:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
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 at 13:19

1 Answer 1

up vote 6 down vote accepted

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
share|improve this answer
    
Worked like a charm.. I have a little further requirement.. I will try that myself and see how it goes.. Thank you so much.. –  Being Gokul Feb 13 at 14:22

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