PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > how to fix nested comment with sed?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

how to fix nested comment with sed?

Réponse
 
LinkBack Outils de la discussion
Vieux 10/09/2007, 06h55   #1
Adam
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut how to fix nested comment with sed?

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.

  Réponse avec citation
Vieux 10/09/2007, 23h00   #2
Rob S
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to fix nested comment with sed?

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 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!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Réponse avec citation
Vieux 11/09/2007, 09h24   #3
Rakesh Sharma
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h52.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11049 seconds with 11 queries