如何在Linux中存储diff的结果
如何在对文件 A.txt 和 B.txt 应用 diff 后获取另一个文件的结果。
假设文件 A.txt 有:
a
b
c
文件 B.txt 有:
a
b
运行
diff A.txt B.txt 它给出的结果为 c,但如何将其存储在文件 C.txt 中?
How to get the result on another file after applying diff to file A.txt and B.txt.
Suppose File A.txt has:
a
b
c
File B.txt has:
a
b
on running
diff A.txt B.txt
It gives result as c, but how to store it in a file C.txt?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
diff
实用程序在标准输出(通常是控制台)上生成其输出。与执行此操作的任何 UNIX 实用程序一样,它的输出可以非常简单地重定向到如下文件中:这意味着“使用两个参数执行命令
diff
(文件A.txt
> 和B.txt
),并将控制台上显示的所有内容放入文件C.txt
中”。错误消息仍然会发送到控制台。要将
diff
的输出保存到文件并也将其发送到终端,请使用tee
,如下所示:tee 会将数据复制到所有命名文件(此处仅
C.txt
)以及标准输出(很可能是终端)。The
diff
utility produces its output on standard output (usually the console). Like any UNIX utility that does this, its output may very simply be redirected into a file like this:This means "execute the command
diff
with two arguments (the filesA.txt
andB.txt
) and put everything that would otherwise be displayed on the console into the fileC.txt
". Error messages will still go to the console.To save the output of
diff
to a file and also send it to the terminal, usetee
like so:tee will duplicate the data to all named files (only
C.txt
here) and also to standard output (most likely the terminal).使用
>
您可以将输出重定向到文件。例如:这将导致 diff 命令的输出保存在名为 C.txt 的文件中。
Using
>
you can redirect output to a file. Eg:This will result in the output from the diff command being saved in a file called C.txt.
使用输出重定向。
将存储 file1 和 file2 的差异以输出
Use Output Redirection.
will store the diff of file1 and file2 to output
有些文件
diff
可能无法很好地处理输出,例如块特殊文件、字符特殊文件和损坏的链接。由于与这些差异而导致的输出可能会出现标准错误。有趣的是,当我重定向标准错误时,我仍然错过了一些东西:
查看所有结果的唯一方法是:
我正在比较复制到外部硬盘后 live-cd 安装目录的结果
There are some files that
diff
may not do well with the output, like block special files, character special files, and broken links. The output due to differences with these may go to standard error.Interestingly, when I redirected standard error, I still missed some things:
The only way to see the results of everything was to:
I was comparing the results of a live-cd mounted directory after copying to an external HD