logs – How to Write tail -f Output with Comments to a Separate Text File

debugginglogspipetail

The command tail -f command is great for tracing, and in terminal it's very helpful to be able to, for example, hit enter, and type a comment like

-- after xyz change... --

For record purposes, I would like to be able to pipe the tail output to terminal, plus my annotations, to a second file. Is this possible (other than copying and pasting the output manually)? Thanks!

Best Answer

This does what you need:

sh -c 'tail -f file & cat' | tee file2

Note, it duplicates your comments for the terminal output when you press enter.

It works also with {...} and (...) instead of sh -c, but then tail -f won't stop running when you press ctrl+c.

Related Question