使用findstr比较/查找两个文本文件之间的差异 [英] Comparing/finding the difference between two text files using findstr

查看:133
本文介绍了使用findstr比较/查找两个文本文件之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要比较两个文本文件并找出它们之间的区别.基本上,我有一个输入文件(input.txt),该文件将由批处理作业处理,而我的批处理将记录该作业成功运行的输出(successful.txt).

I have a requirement to compare two text files and to find out the difference between them. Basically I have an input file (input.txt) which will be processed by a batch job and my batch will log the output (successful.txt) where the job has successfully ran.

简单来说,我需要找出input.txt和success.txt(input.txt-successful.txt)之间的区别,并且我正在考虑使用findstr.似乎很好,但我不了解其中一部分.它始终在输出中包含我的input.txt的最后一行.您可以在下面的示例中看到这一点.请注意,在我的input.txt的最后一行之后没有空格或换行符.

In simple words, I need to find out the difference between input.txt and successful.txt (input.txt-successful.txt) and I was thinking to use findstr. It seems to be fine, BUT I don't understand one part of it. It always includes the last line of my input.txt in the output. You could see that in the example below. Please note that there is no leading space or line break after the last line of my input.txt.

在下面的示例中,您可以看到在两个文件中都存在行server1,db1,但仍在输出中列出. (它始终是input.txt的最后一行)

In below example, you could see the line server1,db1 is present on both the files, but still listed in the output. (It is always the last line of input.txt)

D:\Scripts\dummy>type input.txt
server2,db2
server3,db3
server10,db10
server4,db4
server1,db11
server10,schema11
host1,sch2
host11,sql2
host11,sql3
server1,db1
D:\Scripts\dummy>type successful.txt
server1,db1
server2,db2
server3,db3
server4,db4
server10,db10
host1,sch2
host11,sql2
host11,sql3
D:\Scripts\dummy>findstr /vixg:successful.txt input.txt
server1,db11
server10,schema11
server1,db1

我在做什么错了?

干杯, G

推荐答案

我可以通过在input.txt的最后一行之后删除换行符来重现您的结果,因此解决方案1是在.由于您似乎说input.txt没有终端换行符,因此添加一个就可以解决此问题; findstr的行为符合预期,因为它在换行符终止的行上起作用.

I could reproduce your results by removing the newline after the last line of input.txt, so solution 1 would be to add a newline to the end of input.txt. Since you appear to say that input.txt has no terminal newline, then adding one would cure the problem; findstr is acting as expected because it acts on newline-terminated lines.

解决方案2应该是

type input.txt|findstr /vixg:successful.txt

这篇关于使用findstr比较/查找两个文本文件之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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