Question: Consider again the sed code of Figure 14.1. It is tempting to write the first of the compound statements as follows (note the differences in
Consider again the sed code of Figure 14.1. It is tempting to write the first of the compound statements as follows (note the differences in the three substitution commands):
![# label (target for branch): :top / < [hH] [123]>.* / {](https://dsd5zvtm8ll6.cloudfront.net/si.question.images/images/question_images/1606/3/7/0/9535fbf468957b551606370953058.jpg)
Explain why this doesn’t work.
Figure 14.1:
![# label (target for branch): :top /< [hH] [123]>.*/ { ;# match whole heading ;# save copy of pattern space ;# delete text after closing tag ;# delete text before opening tag h s/\(\). *$/\1/ s/](https://dsd5zvtm8ll6.cloudfront.net/si.question.images/images/question_images/1606/3/7/2/8805fbf4e10aa42c1606372880110.jpg)
# label (target for branch): :top / < [hH] [123]>.* / { ;# match whole heading ;# save copy of pattern space ;# delete text after closing tag ;# delete text before opening tag h s/\( \). *$/\1/ s/".*\( \)/\1/ ;# print what remains ;# retrieve saved pattern space ;# delete opening tag ;# delete closing tag s/ < [hH] [123]>// s/ // b top ;# and branch to top of script ;# match opening tag (only) / < [hH] [123]>/ { N ;# extend search to next line b top ;# and branch to top of script d. ;# if no match at all, delete
Step by Step Solution
3.42 Rating (155 Votes )
There are 3 Steps involved in it
Because regular expressions in sed are greedy the constructs on line... View full answer
Get step-by-step solutions from verified subject matter experts
