Remove Specific Line from CSV File

I have a dashboard where when the certain ID of a part is entered, I want to delete that line when the button is pressed. I am able to remove the data, but it then outputs as undefined and is not able to leave the output CSV node.

[
    {
        "id": "1aec8b4fbf3e71df",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "aa468a591b7fc34c",
        "type": "csv",
        "z": "1aec8b4fbf3e71df",
        "name": "",
        "sep": ",",
        "hdrin": "",
        "hdrout": "none",
        "multi": "one",
        "ret": "\\n",
        "temp": "hex_output,item_name,quantity,restockquant",
        "skip": "0",
        "strings": true,
        "include_empty_strings": false,
        "include_null_values": false,
        "x": 410,
        "y": 160,
        "wires": [
            [
                "dc6754d55e35c333"
            ]
        ]
    },
    {
        "id": "dc6754d55e35c333",
        "type": "switch",
        "z": "1aec8b4fbf3e71df",
        "name": "",
        "property": "payload.hex_output",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "rfidhex",
                "vt": "flow"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 530,
        "y": 160,
        "wires": [
            [
                "17a172317b9788b3"
            ],
            [
                "5c257a15c743a92c"
            ]
        ]
    },
    {
        "id": "8f995eabfc526153",
        "type": "csv",
        "z": "1aec8b4fbf3e71df",
        "name": "",
        "sep": ",",
        "hdrin": "",
        "hdrout": "none",
        "multi": "one",
        "ret": "\\n",
        "temp": "hex_output,item_name,quantity,restockquant",
        "skip": "0",
        "strings": true,
        "include_empty_strings": true,
        "include_null_values": false,
        "x": 990,
        "y": 160,
        "wires": [
            [
                "1747ea39ef757c0f"
            ]
        ]
    },
    {
        "id": "17a172317b9788b3",
        "type": "change",
        "z": "1aec8b4fbf3e71df",
        "name": "",
        "rules": [
            {
                "t": "delete",
                "p": "payload",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 690,
        "y": 140,
        "wires": [
            [
                "5c257a15c743a92c"
            ]
        ]
    },
    {
        "id": "5c257a15c743a92c",
        "type": "join",
        "z": "1aec8b4fbf3e71df",
        "name": "",
        "mode": "auto",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": true,
        "timeout": "",
        "count": "",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 870,
        "y": 160,
        "wires": [
            [
                "8f995eabfc526153",
                "c0359cfbb2dfbb1f"
            ]
        ]
    },
    {
        "id": "c0359cfbb2dfbb1f",
        "type": "debug",
        "z": "1aec8b4fbf3e71df",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1050,
        "y": 260,
        "wires": []
    },
    {
        "id": "d6f3a342b80c056c",
        "type": "template",
        "z": "1aec8b4fbf3e71df",
        "name": "",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "e0040150c6cd280d,HHCS 1/4-20X1/2,76,300\ne0040150c6cd16ff,HHCS 1/4-20X3/4,91,300\ne0040150c6cd2a81,HHCS 1/4-20X1,80,300\ne0040150c6cd14c3,HHCS 1/4-20X1-1/4,64,250\n",
        "output": "str",
        "x": 280,
        "y": 160,
        "wires": [
            [
                "aa468a591b7fc34c"
            ]
        ]
    },
    {
        "id": "1747ea39ef757c0f",
        "type": "template",
        "z": "1aec8b4fbf3e71df",
        "name": "",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "This is the payload: {{payload}} !",
        "output": "str",
        "x": 1140,
        "y": 160,
        "wires": [
            []
        ]
    }
]

This is my flow for the moment, but it is more intricate on my big file. I am trying to remove the second line based off of the ID (the first column of values).

This is the output I receive when I do click the button on my dashboard in my large project.

I figured it out. You just have to add a function node with this code after the join node.

msg.payload = msg.payload.filter(obj => obj !== undefined);
return msg;

Personally I would do this using operating system utilities - in Linux, the stream editor sed.
It saves reading the file into Node-red, deleting a line and writing it back out again.

[{"id":"afd35866f96a7664","type":"group","z":"1aec8b4fbf3e71df","name":"Passing parameters to a Bash script as environment variables","style":{"label":true},"nodes":["32b53ca9663a2f7a","b9ade47616c81169","fbc7d37039f81c17","3904a3d3cbccc354"],"x":14,"y":691.5,"w":572,"h":129.5},{"id":"32b53ca9663a2f7a","type":"inject","z":"1aec8b4fbf3e71df","g":"afd35866f96a7664","name":"","props":[{"p":"filename","v":"/home/pi/testdata","vt":"str"},{"p":"filter","v":"e0040150c6cd16ff","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":740,"wires":[["b9ade47616c81169"]]},{"id":"b9ade47616c81169","type":"template","z":"1aec8b4fbf3e71df","g":"afd35866f96a7664","name":"Bash script ","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"FILE={{{filename}}}\nFILTER={{{filter}}}\nsed -i /$FILTER/d $FILE","output":"str","x":270,"y":740,"wires":[["3904a3d3cbccc354","fbc7d37039f81c17"]]},{"id":"fbc7d37039f81c17","type":"exec","z":"1aec8b4fbf3e71df","g":"afd35866f96a7664","command":"","addpay":"payload","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"Run the script","x":480,"y":740,"wires":[[],[],[]]},{"id":"3904a3d3cbccc354","type":"debug","z":"1aec8b4fbf3e71df","g":"afd35866f96a7664","name":"Full Script","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":460,"y":780,"wires":[]}]

Or use the recreate message sequence of the switch node .
e.g.

[{"id":"500c83e3d8d65425","type":"inject","z":"1aec8b4fbf3e71df","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":240,"wires":[["d6f3a342b80c056c"]]},{"id":"d6f3a342b80c056c","type":"template","z":"1aec8b4fbf3e71df","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"e0040150c6cd280d,HHCS 1/4-20X1/2,76,300\ne0040150c6cd16ff,HHCS 1/4-20X3/4,91,300\ne0040150c6cd2a81,HHCS 1/4-20X1,80,300\ne0040150c6cd14c3,HHCS 1/4-20X1-1/4,64,250\n","output":"str","x":280,"y":160,"wires":[["aa468a591b7fc34c"]]},{"id":"aa468a591b7fc34c","type":"csv","z":"1aec8b4fbf3e71df","name":"","sep":",","hdrin":"","hdrout":"none","multi":"one","ret":"\\n","temp":"hex_output,item_name,quantity,restockquant","skip":"0","strings":true,"include_empty_strings":false,"include_null_values":false,"x":410,"y":160,"wires":[["dc6754d55e35c333"]]},{"id":"dc6754d55e35c333","type":"switch","z":"1aec8b4fbf3e71df","name":"","property":"payload.hex_output","propertyType":"msg","rules":[{"t":"neq","v":"rfidhex","vt":"flow"}],"checkall":"false","repair":true,"outputs":1,"x":530,"y":180,"wires":[["5c257a15c743a92c"]]},{"id":"5c257a15c743a92c","type":"join","z":"1aec8b4fbf3e71df","name":"","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":650,"y":180,"wires":[["8f995eabfc526153"]]},{"id":"8f995eabfc526153","type":"csv","z":"1aec8b4fbf3e71df","name":"","sep":",","hdrin":"","hdrout":"none","multi":"one","ret":"\\n","temp":"hex_output,item_name,quantity,restockquant","skip":"0","strings":true,"include_empty_strings":true,"include_null_values":false,"x":830,"y":180,"wires":[["1747ea39ef757c0f"]]},{"id":"1747ea39ef757c0f","type":"template","z":"1aec8b4fbf3e71df","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload}}","output":"str","x":1000,"y":180,"wires":[["79d621cad085d009"]]},{"id":"79d621cad085d009","type":"debug","z":"1aec8b4fbf3e71df","name":"debug 324","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1190,"y":180,"wires":[]}]

But @jbudd suggestion is far more efficient

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