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

Re: Substitution par 'sed' une seule fois dans un fichier...



François TOURDE a écrit, dimanche 24 février 2008, à 23:32 :
> Le 13933ième jour après Epoch,
> Sylvain Sauvage écrivait:
> 
> > Sylvain Sauvage, dimanche 24 février 2008, 18:37:49 CET
> >>[???] 
> >>   M???enfin, bon, il y a sûrement d???autres solutions???
> >
> >   Ben oui, il y a plus simple : 0,/xxx/s//yyy/
> >
> > 0,/xxx/ : la commande ne s???applique que de la 1re ligne à celle qui
> >           correspond à /xxx/
> 
> Je crois qu'il vaut mieux traduire ça par: "entre la ligne 1 et la
> première contenant xxx", non?

Non, c'est bien de la ligne 1 à la ligne de la /regexp/, incluses (c'est
peut-être la même) ; le truc de la ligne 0 est une extension GNU.

> > s//yyy/ : remplacer la correspondance par yyy.
> 
> Par contre, je ne vois pas dans la doc que s//yyy/ remplace la
> "correspondance", mais je te crois sur parole (enfin, je ferais un
> test si nécessaire).

 info sed, -> Addresses

     The empty regular expression `//' repeats the last regular
     expression match (the same holds if the empty regular expression is
     passed to the `s' command).  Note that modifiers to regular
     expressions are evaluated when the regular expression is compiled,
     thus it is invalid to specify them together with the empty regular
     expression.
[...]
   GNU `sed' also supports some special two-address forms; all these
are GNU extensions:
`0,/REGEXP/'
     A line number of `0' can be used in an address specification like
     `0,/REGEXP/' so that `sed' will try to match REGEXP in the first
     input line too.  In other words, `0,/REGEXP/' is similar to
     `1,/REGEXP/', except that if ADDR2 matches the very first line of
     input the `0,/REGEXP/' form will consider it to end the range,
     whereas the `1,/REGEXP/' form will match the beginning of its
     range and hence make the range span up to the _second_ occurrence
     of the regular expression.

     Note that this is the only place where the `0' address makes
     sense; there is no 0-th line and commands which are given the `0'
     address in any other way will give an error.

-- 
Jacques L'helgoualc'h


Reply to: