A utility to tail multiple files
tailx only purpose is to tail multiple files and append the filename at the beginning of each line. I created this utility to be used in kubernetes where I want to tail multiple files to the stdout.
tailx file1.txt file2.txt
file1.txt: content in file1.txt
file2.txt: content in file2.txt
-
Just use tail as follows
tail -F file1.txt file2.txt
This will output as follows:
==> file1.txt <== content in file1.txt ==> file2.txt <== content in file2.txt
-
Use tail with awk (see this post)
tail -F file1.txt file2.txt | awk '/^==> / {a=substr($0, 5, length-8); next} {print a": "$0}'
This will output as follows:
file1.txt: content in file1.txt file1.txt: file2.txt: content in file2.txt file2.txt:
NOTE: The empty lines are part of the section separator, not the actual content of the files.