Here is a flow that reads a flows file, rationalises debug nodes that are named debug nnn
and writes a new flows file with the renumbered nodes. Set the input and output path in the inject node, deploy it and click the inject.
If you are brave and trusting then you can set the output path to the input path and then you just have to restart node-red. However, if you are sane, you will instead write it to a new file, rename the old one, and replace it with the new one, then restart node-red.
[{"id":"2a1220f4e0f4ad64","type":"group","z":"bdd7be38.d3b55","name":"Rationalise debug node numbering","style":{"label":true},"nodes":["4cbc1bf30977dc4d","b6c70c743e51889d","8b2ca0887d7c0a3e","5b51b44a83135ec3","fefb82892cbc35d0","e60ea84d9655fc06","f6a6e6641bad366a"],"x":174,"y":3339,"w":972,"h":202},{"id":"4cbc1bf30977dc4d","type":"inject","z":"bdd7be38.d3b55","g":"2a1220f4e0f4ad64","name":"Configure paths in here","props":[{"p":"flowfilePath","v":"/full/path/to/flows.json","vt":"str"},{"p":"outPath","v":"/full/path/to//flows.new.json","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":320,"y":3380,"wires":[["b6c70c743e51889d"]]},{"id":"b6c70c743e51889d","type":"file in","z":"bdd7be38.d3b55","g":"2a1220f4e0f4ad64","name":"Read flow file","filename":"flowfilePath","filenameType":"msg","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":550,"y":3380,"wires":[["5b51b44a83135ec3"]]},{"id":"8b2ca0887d7c0a3e","type":"debug","z":"bdd7be38.d3b55","g":"2a1220f4e0f4ad64","name":"debug 14","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":3500,"wires":[]},{"id":"5b51b44a83135ec3","type":"json","z":"bdd7be38.d3b55","g":"2a1220f4e0f4ad64","name":"","property":"payload","action":"","pretty":false,"x":750,"y":3380,"wires":[["fefb82892cbc35d0"]]},{"id":"fefb82892cbc35d0","type":"function","z":"bdd7be38.d3b55","g":"2a1220f4e0f4ad64","name":"Rationalise debug node names","func":"// msg.payload should include a flow file as an array of objects\nlet debugNumber = 1\nmsg.payload = msg.payload.map(rationalise) \nreturn msg;\n\nfunction rationalise(item) {\n let answer = item\n if (item.type === \"debug\") {\n // check for name \"debug nnn\"\n if (item.name.match(/debug [0-9]+$/)) {\n //node.warn(`matching debug node found: ${JSON.stringify(item)}`)\n // Change the name to an incrementing debug number\n answer.name = `debug ${debugNumber++}`\n //node.warn(`changed to: ${JSON.stringify(answer)}`)\n }\n }\n return answer\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":990,"y":3380,"wires":[["f6a6e6641bad366a"]]},{"id":"e60ea84d9655fc06","type":"file","z":"bdd7be38.d3b55","g":"2a1220f4e0f4ad64","name":"Write flow file","filename":"outPath","filenameType":"msg","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":730,"y":3460,"wires":[["8b2ca0887d7c0a3e"]]},{"id":"f6a6e6641bad366a","type":"json","z":"bdd7be38.d3b55","g":"2a1220f4e0f4ad64","name":"","property":"payload","action":"","pretty":true,"x":550,"y":3460,"wires":[["e60ea84d9655fc06"]]}]