Forum Discussion
I can’t think of a way to do that directly, but what if you were to use a Mapper snap to add the value of that variable to the input document of the Script snap?
Hi Smitha,
This should be possible. Try and look at this example and see if you can adapt it to for your needs.
The mapper can be used to conveniently alter binary data before parsing. See the “views” section in the Mapper documentation.
In the attached pipeline, the mapper is using binary views, converting the input data to a string, then replacing the
\r\n
to a space charactercr-example.zip (3.1 KB)
Hi tlikarish,I have tried the approach you have suggested, since as you see in the attached snapshot the record spans over multiple line and there is only CR in one of the columns in between, I have changed the expression to replace -$content.toString().replace(‘\r’, ’ '), by this the records did not get loaded properly, the records was still not considered as single record.
Can you let us know if we need to do something elseThanks
Regards
smitha csvparser.zip (25.5 KB)Are you seeing an error message? Since you’re using quotes and the column is quoted, the CSV Parser should treat the carriage return as part of the column’s value and not as a row delimiter. Is it possible the quoting is off?
Doh – also messed up with the expression I gave you.
$content.toString().replace('\r', ' ')
Only replaces the first match. You should probably use
replaceAll
or change the regular expression to/\r/g
. This will replace all carriage returns, so if the lines are delimited with\r\n
, then you’d have to use something like/\r(?!\n)/g
, which would remove all carriage returns not followed by a line feed.