Gsub - Replace windows line terminators (\r\n) with unix (\n)

Hi,
I am trying to format a csv file so that it can be used in the translate filter.
the csv file has only two columns (comma separated) with windows line ending format (CRLF)
which somehow causes the translate filter to throw an error --> "Unquoted fields do not allow \r or \n"

So, i attempted to use gsub to format the file to have Unix (LF) like the below.

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

However, Although translate does not throw an error anymore, i dont think this is working since when i cat or nano the file...i see the contents in one long line like --> value1,value2\nvalue3,value4\nvalue5,value6....
instead of
value1
value2
value3
value4
value5
value6

Also, filters like cidr seem to throw an error saying it could not find valid network called "\n" which furthers the above assumption that it is somehow it is not able to "detect" an actual newline in the file.

I also tried various combinations like
gsub => [ "message", "\r\n", "\n" ]
gsub => [ "message", "\\r\\\n", "\n" ]
etc. but none of them worked

Any assistance would be appreciated

Thanks in advance!

Update:
I think the below is working to replace CRLF with LF

gsub => [ "message", "\r", ""]

i did a cat -A myfile.csv and the output is like the below ($ stands for newline/LF i believe in cat -A)

value1,value2$
value2,value3$
value4,value5$
$

However, now i get a different error with translate filter on the file
exception=>#<LogStash::Filters::Dictionary::DictionaryFileError: Translate: no implicit conversion of nil into String when loading dictionary file

Update2:
The extra LF at the end ($) was the issue. I think i got it working with the below

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


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