Note that there are some explanatory texts on larger screens.

plurals
  1. POUse Bash (sed?) to remove a multiline /* ... */ style comment containing specific text (regex)
    primarykey
    data
    text
    <p>I am looking for a bash solution to remove a code snippet that contains information that is now considered superfluous in /* ... */ comments in java classes.</p> <p>Specifically, previously when we checked in our code, it would automatically add near the top of the class a copy of the check in history:</p> <pre><code>/* Copyright statement */ /* * $Log: * 3 Project1 02/02/2012 19:05:59 Bob Geldof * Comment 3 * 2 Project1 01/02/2012 15:25:22 Sir Lancelot * CR-12345 * 1 Project1 22/10/2011 12:15:31 Thomas the Tank Engine * First implementation of that cool thing * $ */ package com.thing.place.blah ... ... ... </code></pre> <p>We now use different tools that better display this information, and using code comparisons between projects that reuse code is a pain due to difference in timestamps, comments etc.</p> <p>Currently, if we work on a file, we manually remove the comment statement and the $Log: keyword that generates the statement, however what I would like to do is write a script to remove them accross all java files. I'm fine with the bash script to run it on every java file, however there are a couple of tricks here in the regex that I'm not aware on how to implement.</p> <p>So I guess the workflow is something like</p> <ol> <li>Look for the first <em>"$Log:"</em> in the file</li> <li>Look for the closest <em>"/*"</em> preceeding this text</li> <li>Look for the closest <em>"*/"</em> after this text.</li> <li>Remove all text in between and including the <em>"/*"</em> and the <em>"*/"</em></li> <li>Do this without removing any comments prior/after (most files will have a similarly formatted copyright statement above, potentially with the end comment and start comment tags on the same line such as <em>" ... end of copyright text */ /* $Log: ..."</em></li> </ol> <p>In order to do this, I would prefer regex arguments compatible with sed as this is what I'm familiar with using, although I'll take whatever you have to offer! Also if it makes sense to make multiple passes, such as "remove between start tag and $Log:", "remove between end tag and $Log:", "remove $Log:" that would be fine. This is a one time process so speed is much less important than accuracy.</p> <p>Many thanks for any suggestions. Mitch.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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