如何在Linux中存储diff的结果 [英] How to store result of diff in Linux

查看:213
本文介绍了如何在Linux中存储diff的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将diff应用于文件A.txt和B.txt之后,如何在另一个文件上获得结果.

How to get the result on another file after applying diff to file A.txt and B.txt.

假设文件A.txt具有:

Suppose File A.txt has:

a
b
c

文件B.txt具有:

a
b

正在运行

diff A.txt B.txt 它给出的结果为c,但是如何将其存储在C.txt文件中?

diff A.txt B.txt It gives result as c, but how to store it in a file C.txt?

推荐答案

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

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

这意味着使用两个参数(文件A.txtB.txt)执行命令diff,并将原本会在控制台上显示的所有内容放入文件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.

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

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会将数据复制到所有命名文件(此处仅C.txt)和标准输出(很可能是终端)中.

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

这篇关于如何在Linux中存储diff的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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