Branching (condicional).

Solo es posible realizar este tipo de test cuando se realiza una substitución exitosa.

[address]t[label]

Si no se especifica una etiqueta, cuando se cumpla la condición será enviado al final del script.

Escenario

Queremos hacer el remplazo de un carácter en todas las líneas. Una vez que se realice, pasamos a la siguiente.

La letra más utilizada en el alfabeto es la 'a'. Para efectos de demostración emplearemos el control de flujo (branch) en la substitución de ésta letra por XXX.

Entrada

Consult Section 3.1 in Owner and Operator
Guide for a description of the tape drivers
available on your system.
blank
Look in the Owner and Operator Guide shipped with your system.
blank
Two manuals are provided and including the Owner and
Operator Guide and the User Guide.
blank
The Owner and Operator Guide is shipped with your system.


Sed script

:again
   s/a/XXX/
   t again


Salida

[lyonn@mictlan 6]$ sed -f branching.sed multiline.txt
Consult Section 3.1 in Owner XXXnd OperXXXtor
Guide for XXX description of the tXXXpe drivers
XXXvXXXilXXXble on your system.
blXXXnk
Look in the Owner XXXnd OperXXXtor Guide shipped with your system.
blXXXnk
Two mXXXnuXXXls XXXre provided XXXnd including the Owner XXXnd
OperXXXtor Guide XXXnd the User Guide.
blXXXnk
The Owner XXXnd OperXXXtor Guide is shipped with your system.








Por supuesto que es el mismo efecto que si incluyéramos el global replacement, sin embargo, los usos para propósitos diferentes.



Comentarios

Entradas populares