与diff比较并格式化输出

时间:2016-05-15 11:52:38

标签: git shell

我使用diff接收两个文件,有没有一种方法可以格式化输出,所以它可以说,文件名:Ascii在块大小:1000更改?而不是仅将所有更改转储到文件的常规输出。

 File A:
    File Type: regular file
    File Path: ./Secrets/711wasaparttimejob/Ascii
    File Name: Ascii
    Access Mode: -rw-r--r--
    Owner ID: 1000
    Group ID: 1000
    Block Size: 2311
    Last Modified: 2016-05-13 13:38:52.904210046 +0000
    Status Change: 2016-05-13 13:38:52.904210046 +0000
    Last Access: 2016-05-15 10:38:58.015821340 +0000
    MD5: 317ddabf4a1bd79c2ac491dba6634cb0 ./Secrets/711wasaparttimejob/Ascii


    File B:
    File Type: regular file
    File Path: ./Secrets/711wasaparttimejob/Ascii
    File Name: Ascii
    Access Mode: -rw-r--r--
    Owner ID: 1000
    Group ID: 1000
    Block Size: 1000
    Last Modified: 2016-05-13 13:38:52.904210046 +0000
    Status Change: 2016-05-13 13:38:52.904210046 +0000
    Last Access: 2016-05-15 10:38:58.015821340 +0000
    MD5: 317ddabf4a1bd79c2ac491dba6634cb0 ./Secrets/711wasaparttimejob/Ascii

1 个答案:

答案 0 :(得分:1)

您可以重定向diff命令的输出,然后使用 grep -E 使用正则表达式搜索您想要输出的内容。

例如,我将您的文字粘贴到文件中。然后使用:

cat second.txt | grep -E "File Name|Block Size"                                  

打印出来:

File Name: Ascii
Block Size: 2311
File Name: Ascii
Block Size: 1000

cat只输出文件的所有内容。在您的情况下, cat second.txt 将被您的diff命令替换。

git diff ... | grep -E "File Name|Block Size"