Node-RED version: v2.0.5
Node.js version: v14.16.0
macOS Big Sur v11.6
I have a file I split on '\n's and then want to remove all lines that start with a #
and join the remaining lines. Normally I split the files and use a switch
node to eliminate the ones I don't want and have a delay
node that sends a 'msg.complete' to the join. For example, if the file is this:
# test file
line 1
# remove me
line 2
line 3
# remove me too
the end result should be
line 1
line 2
line 3
I'm experimenting to see if I can eliminate the switch
and need for the delay
to tell the join
it's all finished. In the example flow below I use an inject
node with \\
as the line breaks and split on the \\
's but I can't figure out how to ignore the lines that start with #
.
[{"id":"3f556a5b754ab050","type":"join","z":"5cba28c9e0847a85","name":"","mode":"reduce","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"","reduceRight":false,"reduceExp":"$contains(payload, '#')\t","reduceInit":"","reduceInitType":"str","reduceFixup":"$string($A+payload)","x":1010,"y":320,"wires":[["70b198c0516212a2"]]},{"id":"fdbc9371a9b02ced","type":"inject","z":"5cba28c9e0847a85","name":"JOIN using 'reduce sequence' and strings example","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"# test file\\\\line 1\\\\# remove me\\\\line 2\\\\line3\\\\# remove me too","payloadType":"str","x":1030,"y":200,"wires":[["89c3b84a1977c75c"]]},{"id":"70b198c0516212a2","type":"debug","z":"5cba28c9e0847a85","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1010,"y":380,"wires":[]},{"id":"89c3b84a1977c75c","type":"split","z":"5cba28c9e0847a85","name":"","splt":"\\\\","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":1010,"y":260,"wires":[["3f556a5b754ab050"]]}]
All the 'expressions' I've used end up with a code: "T2001"
Error at evaluateNumericExpression (/usr/local/lib/node_modules/node-red/node_modules/jsonata/jsonata.js:4095:25)
Is it possible to use the 'reduce sequence' with strings and if so are there any examples?