[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: feature request: tail -H
From: |
Pádraig Brady |
Subject: |
Re: feature request: tail -H |
Date: |
Mon, 16 Nov 2015 14:27:05 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
On 01/10/15 17:07, Pádraig Brady wrote:
> On 30/09/15 12:45, Stephen Shirley wrote:
>> Hi,
>> 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.
>
> I like that. It would be similar to the grep option: -H, --with-filename
>
> You could do it with something like:
>
> $ tail -f .bashrc .vimrc | grep --line-buffered -e'^==> .* <==$' -e 'gco'
> ==> .bashrc <==
> alias gco='git checkout'
> ==> .vimrc <==
>
> However that would impact counting, and show redundant headers.
I was going to look at this this evening, and coincidentally
just noticed this pull request for a similar feature:
https://github.com/coreutils/coreutils/pull/4
Now that also incorporates timestamping and coloring,
neither of which is warranted I think, as they
can be added in more general manner outside of tail.
For example the timestamping case was discussed recently at:
http://lists.gnu.org/archive/html/coreutils/2015-11/msg00003.html
grep has coloring internally as it provides functionality
not possible outside, by coloring the extent of the match etc.,
and the file name coloring is just an ancillary albeit useful extension.
cheers,
Pádraig.
- Re: feature request: tail -H,
Pádraig Brady <=