@OP It's not clear what you have against the suggestion of @nick-odell. He seems to have posted a very helpful link in his comment. I think I can see why Multitail from that link would not do exactly what you want, but as far as I can see its top answer, https://unix.stackexchange.com/a/337779, would. This uses GNU Parallel, which should be available to install from the standard repositories of most distributions.
That answer, made by user @cartoonist, stated that the command-line option --line-buffer
was in alpha testing. That was 8 years ago, and things have obviously moved on, because parallel(1)
no longer labels it as such.
My own adaption of that answer for your situation would be to use something like:
parallel --tagstring {/}: --line-buffer tail -f {} ::: * | sed -e '/str[12]/d' -e 's/\t//'
Some bits of explanation about this:
--tagstring {/}:
- prepend the file basename to each line
::: *
- process all files in the current directory - you may not want to do this, and you could use whatever file globbing expression you wished here
sed -e '/str[12]/d'
- delete all lines containing str1
or str2
from the output
sed -e 's/\t//'
- delete the first tab in each line - overcoming a somewhat annoying feature of Parallel
(Slightly to my surprise, I found that the above command, as written, does not need shell metacharacters to be quoted and even handles filenames containing spaces. Must be to do with Parallel being a - rather large - Perl script which must slurp the command line and process it itself, rather than leaving that up to the shell.)