Как исключить "DEBUG" без выбрасывания "BUG" в grep

git clone https://github.com/brektrou/rtl8821CU.git

попробуйте это, так как для этого чипсета нет официального драйвера Linux:(

3
06.08.2020, 16:48
1 ответ

Предполагая, что GNUgrep(используется по умолчанию в Linux ), вы можете использовать режим PCRE и отрицательный просмотр назад:

$ grep -niP '(?<!de)bug|(?<!other)stuff|error' dummy.log 
3:!bug
6:12345 DEBUG bug occured
7:please report BUG to me
8:the filename is critical_bug.log
9:bug should be fix.
11:throws error
12:a stuff
14:c otherstuff stuff

Используемые опции::

-n, --line-number
    Prefix each line of output with the 1-based line number within 
        its input file.

-i, --ignore-case
    Ignore case distinctions in patterns and input data, so that
    characters that differ only in case match each other.

-P, --perl-regexp
    Interpret  PATTERNS  as  Perl-compatible regular expressions (PCREs).
    This option is experimental when combined with the  -z  (--null-data)
    option, and grep -P may warn of unimplemented features.

Волшебство происходит в ретроспективе. Общий формат — (?!<foo)bar, что означает «соответствовать bar, но только , если ему не предшествует foo». Таким образом, (?<!de)bugбудет соответствовать bug, если только оно не идет после de, а (?<!other)stuffбудет соответствовать stuff, если оно не идет после other.

4
18.03.2021, 23:14

Теги

Похожие вопросы