Re: how to fix nested comment with sed?
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 <Jiang.A...@gmail.com> 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 me with this?
> sorry about my poor English.
|