본문 바로가기

인프라,데이터/Fluentd, Fluent Bit

Remove last n characters using Regex & Fluent Bit

I took a quite a munutes to find "remove / delete last n characters / words by regex" but there was no explicit answer.

However, I found a solution.

    [FILTER]
        Name          parser
        Match         test.*
        Key_Name      path
        Parser        removelastn
        Reserve_Data  On
        Preserve_key  On
    [PARSER]
        Name removelastn
        Format regex
        Regex (?<log>.*?).{6}$

link

(?<log>.*?) means "log" might not exist, anyway it catch all characters or nothing("")

.{6}$ means last 6 characters.

if you using this way, you don't need a replacer. you can erase last n words just by simple regex itself.