忽略顺序比较两个文件 [英] Compare two files ignoring order

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

问题描述

我有两个文件,行的顺序无关,我想比较其内容.

I have two files which the order of lines is irrelevant, and I want to compare its content.

我查看了 diff 文档,但找不到类似 --ignore-order 的内容.

I looked into diff documentation but could not find anything like --ignore-order.

有什么建议吗?

推荐答案

先对文件进行排序:

$ sort file1 > file1.sorted
$ sort file2 | diff - file1.sorted

此外,虽然我个人不鼓励这种事情,但如果您使用 bash 并且在您的系统上启用了此功能,您可以通过使用进程替换来避免临时文件:

Also, although I personally discourage this sort of thing, if you are using bash and this feature is enabled on your system you can avoid the temporary file by using a process substitution:

$ diff <(sort file1) <(sort file2)

这篇关于忽略顺序比较两个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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