Arno Schuring wrote: > lina (lina.lastn...@gmail.com on 2011-12-19 23:53 +0800): > > > sed -n '/^model 1/q;/^model 0/,$p' > > > > Just realize the sed -n '/model 0/,/model 1/'p can also do that. (so > > newbie I was/am). > > > > just still don't understand above sentence. sed -n '/^model > > 1/q;/^model 0/,$p' > > The semicolon separates two commands. The first one matches on model 1, > and quits sed (stops processing). The second one is a range command, > matches from the model 0 line to the end of the file ($), and prints > the current line. > > Arguably, the single range command (/model 0/,/model 1/) is a better > solution because it also works in the aggregate case (cat *|sed instead > of sed *).
I would normally prefer /pattern/,/pattern/ except that would not have met the specification of the problem in this particular case. :-) Time for a good plug for Test Driven Design! When practicing TDD the desired result makes a good test case. Then when implementing the code for it the test case would fail if it didn't provide the data that was asked for in the problem specification. Or in this case if it provided more data than asked for in the specification. Bob
signature.asc
Description: Digital signature