Gsub remove square bracket

I'm trying to remove square bracket from my string using gsub filter.

The string is something like this:
'["/path/to/1","/path/to/2"]'

I tried different ways to remove the square bracket "[" and "]" in order to get a string like '"/path/to/1","/path/to/2"'.

At first simply tried

gsub => [
    "document_images", "[", "",
    "document_images", "]", ""
]

Then I tried escaping the "[" with \ and \ but always get an exception at gsub filter.
I also tried

gsub => ["document_images", "[\[\]]", ""]

Again without success.

The same thing works using ruby gsub function:

'test['.gsub('[', '')

Any suggestions?

input { generator { count => 1 lines => [ '["/path/to/1","/path/to/2"]' ] } }
filter { mutate { gsub => [ "message", "[\[\]]", "" ] } }
output { stdout { codec => rubydebug { metadata => false } } }

produces

   "message" => "\"/path/to/1\",\"/path/to/2\"",

for me.

filter { mutate { gsub => [ "message", "\[", "" ] } }

also works. What exception are you getting?

The problem was in the syntax. I was using multiple filters (gsub and split) under the same mutate. Thanks.

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