A simple way to check if an input matches an entry in a text file

A simple way to check if a value is contained in text file.

[{"id":"e025a6f.56cead8","type":"file in","z":"5811904c.b5318","name":"List Of Team Members","filename":"/Users/tim/Desktop/teammembers.txt","format":"utf8","x":764,"y":255,"wires":[["dae4c5b9.339c28","25ee17ce.92e9"]]},{"id":"dae4c5b9.339c28","type":"function","z":"5811904c.b5318","name":"Check for Match","func":"var arrayOfTextEntries = msg.payload.split(\";\");\nvar entryToLookFor = msg.entryToLookFor;\nif (arrayOfTextEntries.indexOf(entryToLookFor)>=1){\n    msg.found = true;\n} else {\n    msg.found = false;\n}\nreturn msg;","outputs":1,"noerr":0,"x":757,"y":404,"wires":[["5ef30987.1894a8"]]},{"id":"dabed1d5.fda648","type":"inject","z":"5811904c.b5318","name":"String to check for","topic":"","payload":"[email protected]","payloadType":"str","repeat":"","crontab":"","once":false,"x":141,"y":256,"wires":[["d6ab0cc1.e24078"]]},{"id":"d6ab0cc1.e24078","type":"function","z":"5811904c.b5318","name":"Format msg for later check","func":"msg.entryToLookFor = msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":395,"y":256,"wires":[["e025a6f.56cead8"]]},{"id":"5ef30987.1894a8","type":"debug","z":"5811904c.b5318","name":"","active":true,"console":"false","complete":"found","x":1039,"y":405,"wires":[]},{"id":"25ee17ce.92e9","type":"debug","z":"5811904c.b5318","name":"","active":true,"console":"false","complete":"false","x":1040,"y":255,"wires":[]},{"id":"706f96fc.fe8ec","type":"comment","z":"5811904c.b5318","name":"A simple way to check if an input matches an entry in a text file","info":"","x":277.5,"y":152,"wires":[]},{"id":"2894ccfa.6c994c","type":"comment","z":"5811904c.b5318","name":"Output the contents of the file for testing purposes","info":"So that we can check we have found the file and what it contains","x":1157.5,"y":210,"wires":[]},{"id":"ad8a618e.5ea59","type":"comment","z":"5811904c.b5318","name":"Have we found the string in the file?","info":"","x":1111.5,"y":369,"wires":[]},{"id":"8488d230.48f27","type":"comment","z":"5811904c.b5318","name":"Full path to your text file","info":"eg /Users/tim/Desktop/teammembers.txt\n\nThis flow is written to accept a text file \nwith entries separated by semi-colons eg.\n\[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];\n\nThe separator is defined and can be changed in the split function within the Check for Match function","x":774.5,"y":212,"wires":[]},{"id":"8f04fe63.b52cc8","type":"comment","z":"5811904c.b5318","name":"Add an entryToLookFor value to the msg object","info":"","x":455.5,"y":213,"wires":[]},{"id":"286bcc2.b1f9334","type":"comment","z":"5811904c.b5318","name":"Convert the string returned by the file node to an array and check if msg.entryToLookFor is in that array","info":"","x":1019.5,"y":448,"wires":[]}]

Flow Info

Created 7 years, 10 months ago
Updated 7 years, 9 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • comment (x6)
  • debug (x2)
  • file in (x1)
  • function (x2)
  • inject (x1)

Tags

  • file
  • contains
  • check
  • lookup
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option