Note that there are some explanatory texts on larger screens.

plurals
  1. POMethod to strip C comments from patch files
    primarykey
    data
    text
    <p>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.</p> <p>How would you write a regex or sed command to search diff patch files for comments and replace comment lines with blank spaces. </p> <p>This works sed regex works for C files, but for patches I need something different:</p> <pre><code>sed '/^\/\*/,/\*\//d' </code></pre> <p>An example patch exerpt would be:</p> <pre><code>@@ -382,7 +391,109 @@ return len; } +/********************************************************************************** + * Some patch + * Author: Mcdoomington + * Do somethimg + * + * fix me + **********************************************************************************/ </code></pre> <p>Anyone have ideas?</p> <p>Edit:</p> <p>Using this filter:</p> <pre><code>sed -e 's,^+ \*.*,+ \/\/Comment removed,' mypatch.patch &gt; output +/********************************************************************************** + //Comment removed + //Comment removed + //Comment removed </code></pre> <p>How do I add a if line ends with \ to skip it?</p> <p>Edit: Solution </p> <p>While not the cleanest way - I used sed with a jury-rigged regex.</p> <pre><code>sed -e '/[^\*\/]$/{N;s,^+ \* .*,+ \* Comment removed,;}' patch &gt; output sed -e '/[^\*\/]$/{N;s,^+\\\* .*,+ \/\* Comment removed,;}' patch &gt; output </code></pre> <p>Note the second command can be a bit too greedy, but for the purposes of sanitizing comments - this works!</p> <p>How it works:</p> <p>1.) First command To determine if this is the end of a comment /[^*/]$/ determines if it is <em>/ then {N;s,^+\* .</em>,+ /* Comment removed,;}' finds +* (whatever) and replaces it with * Comment removed. </p> <p>2.) Second command To determine if this is the end of a comment /[^*/]$/ determines if it is <em>/ then {N;s,^+\* .</em>,+ /* Comment removed,;}' finds + * (whatever) and replaces it with * Comment removed. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload