[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [HS] un pti coup de sed ..?



Steve a écrit, mardi 3 mai 2005, à 11:16 :
> Le mardi 03 mai 2005 à 09 h 49, Jacques a dit:
> > Steve a écrit, mardi 3 mai 2005, à 09:24 :
[...]
> > > J'ai tout un fichier html où j'ai:
> > > 
> > > <p><a href="photo_occasion/alpa30056.htm"> </a></p>
> > > 
> > > et j'aimerai obtenir :
> > > 
> > > <a href="photo_occasion/alpa30056.htm">photo_occasion/alpa30056.htm</a>
[...]
> > > voici ce que j'ai mis :
> > > 
> > > sed -e 's/photo\_occasion\/[a-zA-Z0-9]*\.htm/&">&/' ab.htm
> > > 
> > > mais avec ça j'obtiens :
> > > 
> > > <a href="photo_occasion/zor4.htm">photo_occasion/zor4.htm"> </a>
> > > 
> > > Il y a un "> de trop .... grrr. Pourquoi? Je m'arrête pourtant à
> > > .htm
> > 
> > Ben oui, mais tu remplaces aussi dans l'argument du href, avant le
> > « " » ;
> 
> heu... je ne comprends pas..

Ta  regexp  « photo\_occasion\/[a-zA-Z0-9]*\.htm »  reconnaît la  partie
*entre* les double-quotes :

<a href="photo_occasion/alpa30056.htm">photo_occasion/alpa30056.htm</a>
_________^^^^^^^^^^^^^^^^^^^^^^^^^^^^

et  y  effectue la  substitution  « &">& »,  en  insérant une  troisième
double-quote *avant* le  « "> » final ...  qui se  retrouve donc en trop
dans ton résultat.

> [...] Mais ça ne ressemble pas du tout à ce que j'avais compris de
> sed... faudra que je me plonge encore plus profondément dans la doc..
> 
> > (tu pourrais aussi profiter des options -i et -r de GNU Sed v.4).
> 
> vais voir tout ça.

Info sed plutôt que man ; il y a aussi http://sed.sf.net/, mais ne
plonge pas trop profond sans bouteille ;)
-- 
Jacques L'helgoualc'h



Reply to: