I'm looking at trying to strip out C comments from our patch files and have looked at numerous regexes, but if we remove lines from our patches - it would break them.
How would you write a regex or sed command to search diff patch files for comments and replace comment lines with blank spaces.
This works sed regex works for C files, but for patches I need something different:
sed '/^\/\*/,/\*\//d'
An example patch exerpt would be:
@@ -382,7 +391,109 @@
return len;
}
+/**********************************************************************************
+ * Some patch
+ * Author: Mcdoomington
+ * Do somethimg
+ *
+ * fix me
+ **********************************************************************************/
Anyone have ideas?
Edit:
Using this filter:
sed -e 's,^+ \*.*,+ \/\/Comment removed,' mypatch.patch > output
+/**********************************************************************************
+ //Comment removed
+ //Comment removed
+ //Comment removed
How do I add a if line ends with \ to skip it?
Edit: Solution
While not the cleanest way - I used sed with a jury-rigged regex.
sed -e '/[^\*\/]$/{N;s,^+ \* .*,+ \* Comment removed,;}' patch > output
sed -e '/[^\*\/]$/{N;s,^+\\\* .*,+ \/\* Comment removed,;}' patch > output
Note the second command can be a bit too greedy, but for the purposes of sanitizing comments - this works!
How it works:
1.) First command To determine if this is the end of a comment /[^*/]$/ determines if it is / then {N;s,^+\* .,+ /* Comment removed,;}' finds +* (whatever) and replaces it with * Comment removed.
2.) Second command To determine if this is the end of a comment /[^*/]$/ determines if it is / then {N;s,^+\* .,+ /* Comment removed,;}' finds + * (whatever) and replaces it with * Comment removed.