File comparison

I have 2 text files that I want to periodically compare.
The first file consists of a single word per line - think of this as the master file as it will never change.
The second file also consists of a single word per line, and will contain words from the master file, sometimes not all of them, but never any that the master doesn't contain.
I want a node/flow that both files are fed into and the output message is a list of the words that are missing from the second file.
For example:

Master file:

word_1
word_2
word_3

second file:

 word_2
 word_3

Desired output:
word_1

Thanks for reading

Here is an example, i have used template nodes to simulate file in nodes. Just replace them with file nodes. I have used JSONata in change nodes, but you could also use function nodes and some JS

[{"id":"6061496d.94985","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":2160,"wires":[["ba156bbd.57e338"]]},{"id":"ba156bbd.57e338","type":"template","z":"8d22ae29.7df6d","name":"read file master","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"one\ntwo\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten","output":"str","x":320,"y":2160,"wires":[["418e378f.12ae8"]]},{"id":"418e378f.12ae8","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"master","pt":"msg","to":"$split(payload,\"\\n\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":2160,"wires":[["a626ae2b.a2fcc8"]]},{"id":"a626ae2b.a2fcc8","type":"template","z":"8d22ae29.7df6d","name":"read file slave","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"one\nthree\nfive\nseven\nnine","output":"str","x":180,"y":2220,"wires":[["9a94bc4a.af7d8"]]},{"id":"9a94bc4a.af7d8","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"slave","pt":"msg","to":"$split(payload,\"\\n\")","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"$join($filter(    master,    function($v){$not($v in slave)} ),\"\\n\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":2220,"wires":[["ffd491fb.4123b8"]]},{"id":"ffd491fb.4123b8","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":550,"y":2220,"wires":[]}]
1 Like

Excellent, thank you so much for this.

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