#!/usr/bin/awk -f # print files as if tail -f was running since the beginning # # Non-POSIX tail(1) supports multiple files and printing a "==> filename <==" # header. This gives a different result if you are running tail since 2 minutes # with lines comming from the various files repeating the headers frequently, # or if you re-run tail again on the files. # # This script sorts all lines from the different files, and print the header # whenever the file being printed changes, which give the same output of a # tail -f ... running since the beginning. # # Note that this requires the files'line to already be sorted, such as # containing a timestamp. # # If you use a log with Apr Aug Dec Feb Jan Jun Jul Mar May Nov Sep instead of # a real timestamp, you may convert the dates and pipe it to that script. BEGIN { for (i = 1; i < ARGC; i++) files[ARGV[i]] = "" for (f in files) if ((getline files[f] 0) { for (f in files) if (!(min in files) || files[f] < files[min]) min = f if (last != min) printf("\n==> %s <==\n", min) last = min print(files[min]) if ((getline files[min]