2016-05-15 108 views
1

我使用diff獲取兩個文件,是否有一種方法可以格式化輸出,以便可以說,文件名:Ascii在塊大小:1000更改?而不是常規的輸出,只是轉儲文件的所有更改。與diff比較並格式化輸出

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

你可以重定向從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 second.txt將被diff命令替換。

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