比较 2 个文件并保留两个文件不同的条目 [英] Compare 2 files and keep entries that are not common to both

查看:28
本文介绍了比较 2 个文件并保留两个文件不同的条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 CSV 文件和一个数据库表作为输入.我需要保留数据库表中的所有记录,但排除 CSV 文件中的记录.最后全部写入 CSV 文件.

I have a CSV file and a database table as inputs. I need to keep all the records that are in the database table but exclude those that are in the CSV file. It all gets written to a CSV file in the end.

我所有的尝试都导致了数百次重复,所以我在这里颇受挑战.

All my attempts have resulted in hundreds of duplicates so I'm rather challenged here.

推荐答案

这是一个快速而肮脏的技巧,但它应该适合您的需求.

This is a quick-and-dirty trick, but it should fit your needs.

将您的数据库和您的 CVS 输入连接到 TMap - 使用您的数据库作为主连接,使用 CSV 作为查找.类似的东西:

Connect your database and your CVS input to a TMap- Use your DB as main connection and CSV as Lookup. Something like:

tMySqlInput---->Main--->tMap---out---->tFileDelimitedOutput
                         ^
                         |
                         |
                       Lookup
                         |
                         |
                  tFileDelimitedInput

在 tMap 中,像往常一样映射连接列.单击查找映射区域正上方的扳手并将连接类型设置为内连接.确保匹配模型"未设置为全部,以避免交叉连接.然后,创建out"输出连接.最后,点击这个连接的扳手,将Catch lookup inner join reject"设置为true

Inside the tMap, map the join columns as usual. Click on the wrench just above the lookup mapping area and set the join type as Inner join. Be sure that "Match Model" is not set to All, to avoid cross joins. Then, create the "out" output connection. Finally, click the wrench of this connection and set "Catch lookup inner join reject" to true

在out"(因此,输出文件)上,您将只有数据库中不匹配的行.根据您的数据,您可能需要在 tFileDelimitedOutput 之前添加 tAggregateRow 以最终清除重复项.

On "out" (so, the output file) you will have only the unmatched rows from the DB. Depending on your data, you may need to add a tAggregateRow just before tFileDelimitedOutput to eventually clean duplicates.

这篇关于比较 2 个文件并保留两个文件不同的条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆