如何在Linux中存储diff的结果

发布于 2024-12-09 05:16:52 字数 218 浏览 7 评论 0原文

如何在对文件 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寒江雪… 2024-12-16 05:16:52

diff 实用程序在标准输出(通常是控制台)上生成其输出。与执行此操作的任何 UNIX 实用程序一样,它的输出可以非常简单地重定向到如下文件中:

diff A.txt B.txt >C.txt

这意味着“使用两个参数执行命令 diff(文件 A.txt > 和 B.txt),并将控制台上显示的所有内容放入文件 C.txt 中”。错误消息仍然会发送到控制台。

要将 diff 的输出保存到文件并将其发送到终端,请使用 tee,如下所示:

diff A.txt B.txt | tee C.txt

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:

diff A.txt B.txt >C.txt

This means "execute the command diff with two arguments (the files A.txt and B.txt) and put everything that would otherwise be displayed on the console into the file C.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, use tee like so:

diff A.txt B.txt | tee C.txt

tee will duplicate the data to all named files (only C.txt here) and also to standard output (most likely the terminal).

不即不离 2024-12-16 05:16:52

使用 > 您可以将输出重定向到文件。例如:

    diff A.txt B.txt > C.txt

这将导致 diff 命令的输出保存在名为 C.txt 的文件中。

Using > you can redirect output to a file. Eg:

    diff A.txt B.txt > C.txt

This will result in the output from the diff command being saved in a file called C.txt.

财迷小姐 2024-12-16 05:16:52

使用输出重定向。

比较文件1文件2>输出

将存储 file1 和 file2 的差异以输出

Use Output Redirection.

diff file1 file2 > output

will store the diff of file1 and file2 to output

星光不落少年眉 2024-12-16 05:16:52

有些文件 diff 可能无法很好地处理输出,例如块特殊文件、字符特殊文件和损坏的链接。由于与这些差异而导致的输出可能会出现标准错误。

有趣的是,当我重定向标准错误时,我仍然错过了一些东西:

diff -qr <DirA> <DirB> 2>&1 > mydiff.txt

查看所有结果的唯一方法是:

diff -qr <DirA> <DirB> |tee mydiff.txt

我正在比较复制到外部硬盘后 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:

diff -qr <DirA> <DirB> 2>&1 > mydiff.txt

The only way to see the results of everything was to:

diff -qr <DirA> <DirB> |tee mydiff.txt

I was comparing the results of a live-cd mounted directory after copying to an external HD

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文