InterviewSolution
| 1. |
How Do I Delete Or Change A Block Of Text If The Block Contains A Certain Regular Expression? |
|
Answer» The FOLLOWING deletes the block between 'start' and 'end' inclusively, if and only if the block contains the string 'REGEX'. Written by Russell Davies, with additional comments: # sed script to delete a block if /regex/ matches inside it Note: When the script above reaches /regex/, the entire multi-line block is in the pattern space. To replace ITEMS inside the block, use "s///". To change the entire block, use the 'C' (change) command: /regex/c The following deletes the block between 'start' and 'end' inclusively, if and only if the block contains the string 'regex'. Written by Russell Davies, with additional comments: # sed script to delete a block if /regex/ matches inside it Note: When the script above reaches /regex/, the entire multi-line block is in the pattern space. To replace items inside the block, use "s///". To change the entire block, use the 'c' (change) command: /regex/c |
|