![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| script command | udi | Shell Programming and Scripting | 2 | 09-19-2008 01:15 PM |
| Command taken away from ksh script | hgjdv | Shell Programming and Scripting | 2 | 02-16-2008 09:14 AM |
| Q: Recording shell script screen output using "script" command ? | lalfonso.gomez | Shell Programming and Scripting | 4 | 01-18-2007 06:31 PM |
| reg script command.... | deep | UNIX for Dummies Questions & Answers | 7 | 03-30-2005 08:22 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Sed Script/Command Help
I want to write a sed script/command that will delete my comments from a C++ program.
Basically, I need to delete all the "/* random text */" from a file. How do I go about doing this? I've been reading some stuff online and can't figure it out. Thank you for your help! |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
That:
Code:
sed -e 's;//.*$;;' Code:
sed -e 's/\/\/.*$//' |
|
#3
|
||||
|
||||
|
moxxx68
__________________
moxxx68 http://www.estarinformado.com.ar/apicmaxmiel/bee-diez.gif |
|
#4
|
|||
|
|||
|
Oops. My examples were for // style comments...
|
|
#5
|
||||
|
||||
|
Or to take care of // and /* */ as well as multiline /* */
Code:
#!/usr/bin/sed -nf
# This first case takes care of the following two
# scenarios:
# 1: /* a comment spanning an entire line */
# 2: int code = 1; /* code + comment on same line */
# We are saying search between /* and */, and then
# substitute that for "nothing". So the syntax
# /start/,/end/ searches between start and end.
/\/\*/,/\*\// {
s/\/\*.*\*\///g
}
# take care of multiline comments
# This deletes any lines inclusive. So if a multiline
# comment started on a line with code also, this would
# break.
/\/\*/,/\*\// {
d
}
# now for // style comments
# This just says substitute // followed by any number
# of anything, followed by the end of the line, with nothing.
s/\/\/.*$//g
# print the rest
p
Cheers ZB Last edited by zazzybob; 10-27-2004 at 04:53 AM. |
|
#6
|
||||
|
||||
|
Quote:
could you please explain this syntax.. i am not quite sure what it means.. also in the first example you used a , instead of .* what does the comma do? thanx moxxx68
__________________
moxxx68 http://www.estarinformado.com.ar/apicmaxmiel/bee-diez.gif |
|
#7
|
||||
|
||||
|
No problem. I have recommented my original example above to clarify a few things.
Cheers ZB |
||||
| Google The UNIX and Linux Forums |