Search code examples
linuxunixtail

Multi Tail UNIX


I'm trying to multi tail files using tail -F file1 file2

The output is like this

File1
text from file 1
text from file 1
text from file 1
text from file 1

File2
text from file 2
text from file 2
text from file 2

File1
text from file 1
text from file 1
text from file 1

Is it possible to append the file name to the stream as well ?

example

file1 text from file 1
file2 text from file 2
file1 text from file 1


Solution

  • Pipe the tail output through awk:

    tail -F file1 file2 file3 | awk '/^==>/{f=$2;next} NF>0{print f"  "$0}'