Home » Questions » Computers [ Ask a new question ]

Writing "tail -f" output to another file

Writing "tail -f" output to another file

As a continuation from my last post where I have used grep & tail -f to find occurences of "rare" events. I would like to record this in another file.

Asked by: Guest | Views: 344
Total answers/comments: 2
Guest [Entry]

"Buffering is the problem.

Do it this way,

tail -f log.txt | egrep --line-buffered 'WARN|ERROR' | tee filtered_output.txt
# ^^^^^^^^^^^^^^^

Confirmed to work on Cygwin too."
Guest [Entry]

"When using a command that does not really 'finish' (such as tail -f), this actually does not really work or that well (at all).

You should be able to redirect the output to a text file. Try this:
tail -f log.txt | egrep 'WARN|ERROR' > filtered_output.txt"