如何比较两个 unix 命令的输出以找出差异? [英] How can I compare the output of two unix commands to find the difference?

查看:24
本文介绍了如何比较两个 unix 命令的输出以找出差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想创建新文件.我想完成类似的事情:

I prefer not to create new files. I want to accomplish something similar to:

cmd1 > a
cmd2 > b
cat a b b | sort | uniq -u

但不使用文件 a 和 b.

but without using files a and b.

推荐答案

Unix 实用程序通常是面向文件的,因此没有什么能完全满足您的需求.

Unix utilities are generally file oriented, so nothing quite does what you want.

但是,zsh 可以使用以下语法自动创建临时文件:

However, zsh can autocreate temporary files with the following syntax:

diff =(cmd1) =(cmd2)

它还可以使用

diff <(cmd1) <(cmd2)

然而,许多 diff 对它们的输入调用 lseek(),所以不能使用命名管道.

However, many diffs call lseek() on their input, so won't work with named pipes.

(diff 通常是一个更有用的命令,用于比较与上面的管道非常相似的输出.)

(diff is in general a more useful command for comparing very similar output than your pipeline above.)

有关详细信息,请参阅zshexpn"手册页的进程替换"部分.

See the "process substitution" section of the "zshexpn" man page for more details.

这篇关于如何比较两个 unix 命令的输出以找出差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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