UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 28th, 2005, 01:24 PM
Lillian_J Lillian_J is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 4 Lillian_J User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 3 sec
Reputation Power: 0
Question Question about substitution

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.

Reply With Quote
  #2  
Old April 28th, 2005, 09:06 PM
Lillian_J Lillian_J is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 4 Lillian_J User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 3 sec
Reputation Power: 0
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.

Reply With Quote
  #3  
Old April 28th, 2005, 11:12 PM
SimonGreenhill's Avatar
SimonGreenhill SimonGreenhill is offline
(retired)
Dev Shed God 11th Plane (10000 - 10499 posts)
 
Join Date: Dec 2003
Location: The Laboratory
Posts: 10,101 SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)  Folding Points: 4925 Folding Title: Novice Folder
Time spent in forums: 3 Months 3 Weeks 5 h 49 m 4 sec
Reputation Power: 1331
Facebook
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

Reply With Quote
  #4  
Old April 29th, 2005, 02:39 PM
Lillian_J Lillian_J is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 4 Lillian_J User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 3 sec
Reputation Power: 0
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.

Reply With Quote
  #5  
Old April 30th, 2005, 02:15 PM
Lillian_J Lillian_J is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 4 Lillian_J User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 3 sec
Reputation Power: 0
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:/\*.*\*/::'

Reply With Quote
  #6  
Old April 30th, 2005, 07:28 PM
SimonGreenhill's Avatar
SimonGreenhill SimonGreenhill is offline
(retired)
Dev Shed God 11th Plane (10000 - 10499 posts)
 
Join Date: Dec 2003
Location: The Laboratory
Posts: 10,101 SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)  Folding Points: 4925 Folding Title: Novice Folder
Time spent in forums: 3 Months 3 Weeks 5 h 49 m 4 sec
Reputation Power: 1331
Facebook
hmm.. maybe you could put a list of valid wildchars and include the newline specifier (probably \n)?

Something like: (a-zA-Z0-9\\n)*

Reply With Quote
  #7  
Old May 13th, 2005, 10:18 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,089 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 5 Days 3 h 40 m 34 sec
Reputation Power: 9
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Question about substitution


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway