|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I was wondering if I could get some help. I need to understand how I can look through a file of source code like java or c and delete all comments in that file. I believe that it would look for // (comment) and /* (comment) */. I tried using sed but I couldnt get it to work. Thanks for any help you can give me. |
|
#2
|
|||
|
|||
|
I am trying to do this on the command line if possible but I am unsure that I can do that, if not, I only know csh scripting in case I need to create a script to accomplish this.
|
|
#3
|
||||
|
||||
|
Why would you want to do this? Comments are good
![]() Anyway, I'd look into using something like sed to to a search and replace for regular expressions /* -> */ and // -> newline. --Simon
__________________
|
|
#4
|
|||
|
|||
|
Thanks, I tried sed 's/[//*]/ /g' and that just gets rid of // and /* */ but nothing else. I am hoping to get some advice on how to delete what is after // and within /* and */ . Thanks.
|
|
#5
|
|||
|
|||
|
The only problem that I have now is appending the text between /* and */. My code gets rid of the rest of the comments but doesnt work when /* is on one line and */ is on another. Any ideas on how to do that?
My code: Code:
#!/bin/csh
sed 's://.*$::g \
s:/\*.*\*/::'
|
|
#6
|
||||
|
||||
|
hmm.. maybe you could put a list of valid wildchars and include the newline specifier (probably \n)?
Something like: (a-zA-Z0-9\\n)* |
|
#7
|
|||
|
|||
|
lilian, all this are sed cmd (remember vi uses exactly the same)
The substitution order in the sed cmd-file IS RELEVANT to delete any substring beginning by '//' use s/\/\/.*//g to delete any line containing '//' use /\/\//d to remove anything between '/*' and '*/' NOT on the same line, use /\/\*/,/\*\//d to remove anything between '/*' and '*/' ON the same line, use s/\/\*.*\*\///g not tested but should work ![]()
__________________
working on Solaris[5-9], preferred languages french and C. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Question about substitution |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|