how to fix nested comment with sed?
am 10.09.2007 07:55:53 von Adam
Hi.
I want to editor some c source files with nested comment like
/* COMMENT START
/* and following
/* and following
/* and following
/* and following
/* COMMENT END */
with following sed script.
1,/\/\*/!{ /\*\//,/\/\*/!s/^/>>/; }
but it seems that I can't get the right result like
/* COMMENT START
** and following
** and following
** and following
** and following
** COMMENT END */
would you help me with this?
sorry about my poor English.
Re: how to fix nested comment with sed?
am 11.09.2007 00:00:58 von Rob S
Adam wrote:
> Hi.
> I want to editor some c source files with nested comment like
>
> /* COMMENT START
> /* and following
> /* and following
> /* and following
> /* and following
> /* COMMENT END */
>
> with following sed script.
> 1,/\/\*/!{ /\*\//,/\/\*/!s/^/>>/; }
> but it seems that I can't get the right result like
>
> /* COMMENT START
> ** and following
> ** and following
> ** and following
> ** and following
> ** COMMENT END */
>
> would you help me with this?
> sorry about my poor English.
If each set of comments has START in the first line
sed '/START/!s/\//\*/' commentfile
--
Rob
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
http://www.aspir8or.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Geek by nature, Linux by choice!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Re: how to fix nested comment with sed?
am 11.09.2007 10:24:08 von Rakesh Sharma
sed -e '
#
### fix runaway c-comments
#
## Skip noninteresting line, i.e., one that doesnt contain a /*
\:/\*:!b
## Now we know that this line has a /*.
## Does it also contain a */ in order to make it a valid inline
comment? if yes, then skip it too.
\:/\*.*\*/:b
## Now we know that this is a runaway multiline comment
## Gobble up the following lines till u see a */ in a line or u hit
EOF, in which case we promptly print
## in the pattern space and quit.
:a
$q;N
\:/\*.*\*/:!ba
## perform the substitution /* ---> ** only for second
onwards /* patterns found in the pattern space
:b
s:/\*:**:2
tb
' yourfile
On Sep 10, 10:55 am, Adam wrote:
> Hi.
> I want to editor some c source files with nested comment like
>
> /* COMMENT START
> /* and following
> /* and following
> /* and following
> /* and following
> /* COMMENT END */
>
> with following sed script.
> 1,/\/\*/!{ /\*\//,/\/\*/!s/^/>>/; }
> but it seems that I can't get the right result like
>
> /* COMMENT START
> ** and following
> ** and following
> ** and following
> ** and following
> ** COMMENT END */
>
> would you help me with this?
> sorry about my poor English.