Remove part of message string BEFORE and AFTER config

Hi,

Message: /merlion/dpa2/cn133ta/j4_sryuo/j4_02_sv_ip

I am trying to find a way to remove the strings BEFORE and AFTER a defined string in a message.

In this message, the constant value is dpa2, and I want to discard anything BEFORE dpa2(inclusive), and the "cn133ta/". Only want to retain "j4_sryuo/j4_02_sv_ip".

The position of cn133ta will be of dynamic value, so it is not a constant string. Hope that makes sense.

At the moment, I have tried the gsub below:

mutate { gsub => [ "dir_path", "/[^./]+/tpa2/", "/" ] }

But I'm having trouble finding a way to discard the AFTER string, in this case "cn133ta/".

Thanks

Is it always / separated? Use dissect or grok to break it into fields, then remove_field the ones you don't want.

Yes, its always separated with a "/", since it is really a form of directory structure.

I have found the solution, and that is the below.

mutate { gsub => [ "dir_path", "^.*?/dpa2/[^/]+/", "" ] }

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.