ThomasMcDonald ThomasMcDonald - 6 months ago 27
Bash Question

Compare with diff and format the output

I take in two files with diff, is there a way I can format the output so it could say, File Name: Ascii was changed at Block Size: 1000? Instead of the regular output that just dumps all changes to a file.

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

Answer

You could redirect the output from the diff command and then use grep -E to use regular expressions to search for what you want outputted.

For example I pasted your text into a file. And then used:

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

Which prints out:

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

cat just outputs all contents of a file. In your case cat second.txt will be replaced by your diff command.

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