Suppose I have the following file called Test.java
:
import java.io.*;
/* test comment */
public class Test { /* another test comment */
...
...
...
}
Java programs can contain single-line //
comments and multi-line /* ... */
comments. What I am trying to accomplish is to find /* ... */
comments in Test.java
that occupy a single line and replaces them with a //
comment, in place. So, after replacement, Test.java
should look like this:
import java.io.*;
// test comment
public class Test { // another test comment
...
...
...
}
I tried to do this with sed
by doing the following:
sed -ri 's//\* ([.]*[ ]*) \*//// \1/' Test.java
However, it doesn't seem to change anything. Due to this, I was wondering how do I just replace comments while keeping the rest of the line unchanged? I'm unsure how to accomplish this behavior. I think my regex is off somehow, but I'm not entirely sure why. Any feedback or suggestions would be greatly appreciated.