[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: feature request: tail -H
From: |
Николай Волосатов |
Subject: |
Re: feature request: tail -H |
Date: |
Mon, 16 Nov 2015 17:40:37 +0300 |
Hi,
I've made this changes as part of homework and created pull-request in main
repository on github accidentally. Sorry for that. But if it could be useful
for someone I'll be happy.
Best regards,
Nikolay Volosatov
16.11.2015, 17:27, "Pádraig Brady" <address@hidden>:
> 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.