# File comparison

**URL:** <https://discourse.nodered.org/t/file-comparison/38232>\
**Category:** General\
**Created:** [29 December 2020 19:55 UTC](https://discourse.nodered.org/t/file-comparison/38232 "2020-12-29T19:55:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigmac5753](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigmac5753/32/15733_2.png) [@bigmac5753](https://discourse.nodered.org/u/bigmac5753)\
**Post date:** [29 December 2020 19:55 UTC](https://discourse.nodered.org/t/file-comparison/38232/1 "2020-12-29T19:55:18Z")

</div>

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:

```auto
word_1
word_2
word_3

```

second file:

```auto
 word_2
 word_3

```

Desired output:  
`word_1`

Thanks for reading

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [29 December 2020 21:51 UTC](https://discourse.nodered.org/t/file-comparison/38232/2 "2020-12-29T21:51:42Z")

</div>

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

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![bigmac5753](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigmac5753/32/15733_2.png) [@bigmac5753](https://discourse.nodered.org/u/bigmac5753)\
**Post date:** [30 December 2020 10:16 UTC](https://discourse.nodered.org/t/file-comparison/38232/3 "2020-12-30T10:16:11Z")

</div>

Excellent, thank you so much for this.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 January 2021 10:16 UTC](https://discourse.nodered.org/t/file-comparison/38232/4 "2021-01-13T10:16:12Z")

</div>

Closed on 13 January 2021 10:16 UTC

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