Tail multiple files while piping one of the files through grep

loggingtail

I want to use tail follow two log files, but one of the log files has too much data, so I want it filtered with grep.

tail -f file1 file2|grep mySearch

The issue with this is that both files are run through the grep or rather the output of tail is run through grep. Only file2 should be filtered with the grep of mySearch. Any ideas?

I have tried named pipes, process substitutions, and compound commands.

Best Answer

can you run the two tails in the background, piping the filtered and unfiltered output to a temp file.

Then use that temp file as the source for whatever you need to dos -

tail -f file1 >> temp &
tail -f file2 | grep mySearch >> temp &


do something with temp now