views:

433

answers:

1

Hi guys, I am trying to append formatting to all /* TODO : ... */ tags, but I am having trouble in the multi-line area. I can do single line sed's; but for multiline sed and awk, I don't know.

How do I do this? I'm open to either. Here's what I have so far.

sed 's/\/\/\*[ \t]*TODO[ \t]*:.*/*\//<span style="color:#aaaaaa;font-weight:bold;">&</span>/g'

replace :

int void main ( int h, char * argv[] )
  int a, b; /* TODO :
               - include libraries
               ...
            */
  foobar();
  /* TODO : fix missing {'s */

with :

int void main ( int h, char * argv[] )
  int a, b; <span style="color:#aaaaaa; font-weight:bold;">/* TODO :
               - include libraries
               ...
            */</span>
  foobar();
  <span style="color:#aaaaaa; font-weight:bold;">/* TODO : fix missing {'s */ </span>
+2  A: 
gawk 'BEGIN{
  RS="*/"
  replace="<span style=\"color:#aaaaaa; font-weight:bold;\">"
}
/\/\* +TODO/{
    gsub(/\/\* +TODO/,replace" /* TODO")
    RT=RT "</span>"
}
{ print $0RT}
' file

output

$ ./shell.sh
int void main ( int h, char * argv[] )
  int a, b; <span style="color:#aaaaaa; font-weight:bold;"> /* TODO :
               - include libraries
               ...
            */</span>

  foobar();
  <span style="color:#aaaaaa; font-weight:bold;"> /* TODO : fix missing {'s */</span>
ghostdog74
just as a sidenote: '<span class="todo">' and then use a css section ontop would be better ("stylewise" :)).
akira
I have to have inline styles for this one. ; )
rlb.usa
I don't know GAWK but, this doesn't work so I won't accept it as an answer. I ended up doing it with a really long REGEX to ensure nongreedy matches and ruby's gsub function.
rlb.usa
what doesn't work?? simply saying "doesn't work" isn't very helpful.
ghostdog74