Remove Java code comments
Hi,
Can someone suggest a shell script solution to remove Java comments. I'm able to remove the //.... comments from lines that have no space or text before: Code:
sed '/^\//d' file.java Also I'd like to remove the comments that are within /*.....*/ Any help is appreciated. |
Here's one for the /* ... */. You should be able to modify it to adjust for //.
Code:
[root@log01 tmp]# cat javacomments |
i didn't write the code for you, but ideal (pseudocode )probably like this:
declare linenumberstartcomment=0, linumberstopcomment=0, l=0,begincomment=0; for i in originalfilecontent.java if found "/*" in `echo $i` { linenumberstartcomment=l begincomment=1; } elseif begincomment = 0 || found "*/" in `echo $i` begincomment=0; if begincomment=0 echo $i>> newjava.java l=l+1 next ... something like this. |
Thanks...
I tried twantrd's solution and it works for /*...*/ comments. I'll try turning kstan pseudocode into a shell script and will let you know. |
if you have Python, here's an alternative:
Code:
#!/usr/bin/python Code:
first line /* this is crap */ Code:
# ./test.py |
Quote:
-twantrd |
I think the comment probably in this pattern
/*Developer: alibaba *this is the comment *return int test */ public ...... thats why i give another pseudocode. |
Kstan...
How would you interpret "if found" in a csh script? Thanks |
|
Nice find. Should work for php and javascript code as well :cool:
|
All times are GMT -5. The time now is 08:00 PM. |