如何使用输出获取diff文件名

时间:2014-03-13 21:38:40

标签: diff

有没有办法让diff返回被比较文件的文件名以及输出,例如:

而不是:

17c17
<     free ((qu -> vals) - 1);
---
>     free (qu -> vals);

我正在寻找:

17c17
file1.c
<     free ((qu -> vals) - 1);
---
file2.c
>     free (qu -> vals);

有可能吗?

感谢

1 个答案:

答案 0 :(得分:0)

-u开关确实包含文件名:

#!/bin/bash

echo "    free ((qu -> vals) - 1);" > file1.c
echo "    free (qu -> vals);" > file2.c

diff -u file1.c file2.c

输出:

--- file1.c 2014-03-13 17:46:43.000000000 -0500
+++ file2.c 2014-03-13 17:46:43.000000000 -0500
@@ -1 +1 @@
-    free ((qu -> vals) - 1);
+    free (qu -> vals);