I'd recommend using
awk for this purpose. You can use it as a more powerful
sed by issuing a command such as:
Code:
diff -u files ... | awk '{gsub("^--- ", "Index: Name of file\n=====\n--- "); print $0}'
In this case I am searching for "--- " line in
diff output, then replacing it with "Index: Name of file", followed by a newline, followed by "=====", then a newline, then the original "--- ".
The command
awk can do a lot more, but in this case, it works well as a more flexible
sed, without using something as complex as perl. It is probably slower than
sed, but it can do a lot more as well, such as the following:
Code:
diff -u files ... | awk '{split($0, arr, "^--- "); where = match($0, "^--- ");
val = $0; gsub("^--- ", "Index: ", val); if (where) print (val "\n====="); print $0 }'
(Note that the above should be a one-liner, it is merely broken into multiple lines for readability)
You would have to try it on the output of
diff to see exactly how it works, but as you can see, it is capable of some very sophisticated header formatting for patches, which I found very useful.
(Note that I am mentioning the use of awk here because I couldn't find many good tutorials on the program, and I thought that others might benefit from some examples when used with pipes. I assume that the OP solved their problem long ago...)