There are two ways in sed to avoid specified portions of a document while making the edits everywhere else. You can use the ! command to specify that the edit applies only to lines that do not match the pattern. Another approach is to use the b (branch) command to skip over portions of the editing script. Let's look at an example.
As described in article
to preprocess the input to
so that double dashes
Because program examples are set off by a pair of macros (something like .ES and .EE, for "Example Start" and "Example End"), we can use those as the basis for exclusion.
So you can say:
All of the commands enclosed in braces (
There is another way to accomplish the same thing. The b command allows you to transfer control to another line in the script that is marked with an optional label. Using this feature, you could write the above script like this:
/^\.ES/,/^\.EE/bend s/^"/``/ ... s/\\(em"/\\(em``/g :end
A label consists of a colon (
The b command is designed for flow control within the script. It allows you to create subscripts that will only be applied to lines matching certain patterns and will not be applied elsewhere. However, as in this case, it also provides a powerful way to exempt part of the text from the action of a single-level script.
The advantage of b over ! for this application is that you can more easily specify multiple conditions to avoid. The ! command can be applied to a single command or to the set of commands, enclosed in braces, that immediately follows. On the other hand, b gives you almost unlimited control over movement around the script.