[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature request: tail -H

From: Stephen Shirley
Subject: feature request: tail -H
Date: Wed, 30 Sep 2015 13:45:39 +0200

Here's the scenario: you're in a directory of updating log files
(could be /var/log), and you want to watch all files for specific
keywords. For a single file, "tail -F file | grep keyword" is
sufficient, but if you want to watch multiple files, "tail -F file1
file2 file3 | grep keyword" is much less helpful because you have no
way of knowing which log file the matching text is from.

My suggestion is to add a -H flag (convention taken from grep -H aka
--with-filename) to tail. With -H specified, tail would no longer
print out headers before file contents, it would instead prefix the
line with the file name. With this, "tail -HF file1 file2 file3 | grep
keyword" is useful, because you get the filename included in the
matching lines.

The workaround i've come up with in the meantime is:

  tail -F "$@" | awk '/^$/ {next} /^==>/ {prefix=$2; next} {print
prefix ": " $0}'

but it's a bit of a hack; there's no way to be sure that a header
string is actually a header, and not part of the file contents.

"You are technically correct, the best kind of correct."
- Bureaucrat 1.0, Futurama

reply via email to

[Prev in Thread] Current Thread [Next in Thread]