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]>.* / {

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/

# 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

1 Expert Approved Answer
Step: 1 Unlock

Because regular expressions in sed are greedy the constructs on line... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Language Pragmatics Questions!