两个文件之间的区别 [英] Difference between two files

查看:79
本文介绍了两个文件之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..


i刚刚开始在perl工作...我有一个要求,我需要比较两个文本文件..并需要打印内容在比较到第三个文件期间,文件2中没有...我能够比较文件,但不知道如何将丢失的内容移动到新文件..任何人都可以帮助我做到这一点..使事情清楚所有我想做的是:

展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号

解决方案

嗯,这听起来像是班级的一部分那你正在服用。那是对的吗?无论哪种方式,我们都可以提供协助,但希望看到您迄今为止所尝试的内容。请发布您的代码。


我可以这么说,如果你有Learning Perl,4th Edition,那里有一篇文章介绍了如何比较两个文件并完全按照自己的意愿行事。


另外,如果你没有学习Perl的腼腆,那么请阅读此博客,因为它几乎与书中的比较类型相同。


问候,


Jeff


我可以假设文件file1总是包含比file2更多的元素,或者file2是否可以包含多于file1的那些?


请注意,因为代码在两种情况下都有所不同。


如果一个文件有更多文件,则无关紧要元素比另一个。代码所做的是获取第一个文件并将所有唯一的行放入输出文件中,忽略任何重复。然后,它接受第二个文件,并添加其唯一的行,再次丢弃重复项。


问候,


杰夫

hi all..

i have just now started working in perl... i have a requirment where in i need to compare two text files.. and need to print the contents that are not present in file 2 during comparison into a third file.. i am able to compare files but dont know how to move the missing contents into new file.. can anyone kindly help me in doing it.. to make things clear all i want to do is:

Expand|Select|Wrap|Line Numbers

解决方案

Well, this sounds like it is part of a class that you are taking. Is that correct? Either way, we can assist, but want to see what you have tried thus far. Please post your code.

I can say this, if you have "Learning Perl, 4th Edition", there is a piece in there that goes over how to compare two files and do exactly what you want.

Also, if you don''t have a coy of Learning Perl, then read this blog as it is pretty much the same type of comparison as in the book.

Regards,

Jeff


Can I assume that the file file1 always contain more elements than those of file2 or whether the file2 can contain more elements than those of file1?

Please be clear in that as the code differs in both the cases.


It should not matter if one file has more elements than the other. What the code does is take the first file and put all the unique lines into the output file, disregarding any duplicates. Then, it takes the second file and adds its lines that are unique, again, discarding the duplicates.

Regards,

Jeff


这篇关于两个文件之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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