How to check if record exists in two data sources

Describe the problem/error/question

I have two text files, I want to check if a record exists from File-new exists in File-old. If it exists list them. How can I do this? I tried using the Merge node but I’m unable to get it to display existing records cause I know “Overgeared” exists in File-old but it’s not displaying

This is what’s inside in new.txt

Itaewon Class
Beware the Villainess!
Overgeared
Sword Art Online Re-Aincrad

old.txt

Blue Lock
Commander-in-Chief of the Magic Guild!
Dead Account
Fairy Tail - 100 Years Quest
GACHIAKUTA
Gazing at the Star Next Door
Glasses with a Chance of Delinquent
Hajime no Ippo - Fighting Spirit!
How NOT to Summon a Demon Lord
I Body-Switched With an Evil Hag for 10 Years
I Got My Wish and Reincarnated as the Villainess (Last Boss)!
I Was Reincarnated as the 7th Prince
Overgeared

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • **n8n version:1.89.2
  • **Database (default: SQLite):default
  • **n8n EXECUTIONS_PROCESS setting (default: own, main):default
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):npm
  • **Operating system:Windows Server 2022

one solution would be to use a code node.

you can then extract content from both files and use a JS function like this one:

function getCommonLines(newText, oldText) {
  const newLines = newText.trim().split('\n').map(line => line.trim());
  const oldLinesSet = new Set(oldText.trim().split('\n').map(line => line.trim()));
  
  return newLines.filter(line => oldLinesSet.has(line));
}

can you show me an example workflow on how it’s done?

you can do something like that:

1 Like

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