Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site hropus.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!hropus!ka From: ka@hropus.UUCP (Kenneth Almquist) Newsgroups: net.bugs.usg Subject: Re: Bug in sed(1)? Message-ID: <223@hropus.UUCP> Date: Wed, 22-Jan-86 22:26:35 EST Article-I.D.: hropus.223 Posted: Wed Jan 22 22:26:35 1986 Date-Received: Thu, 23-Jan-86 22:12:13 EST References: <685@ttrdc.UUCP> Organization: Bell Labs, Holmdel, NJ Lines: 40 > I have encountered what I THINK is a bug in sed(1). I would appreciate it > if some wizard more knowing that I would apprise me as to whether it is a > bug or a feature (and whether there is a fix). > > Specifically, it involves expressions of the form '1,/^fixed_pattern$/d' > which when used as the only argument to sed should cause all input lines > from the beginning to the first one which matches fixed_pattern exactly > to be deleted, and the remainder to be printed to stdout. The manual states that: A command line with two addresses selects the inclusive range from the first pattern space that matches the first address through the next pattern space that matches the second. Thus when you say "1,/pattern/d", the first address matches the line 1 of the file, and then checks for lines matching the second address (the /pattern/) starting with line 2 ("the next pattern space" as opposed to the current pattern space). This means that in general if you give two addresses on a sed command, at least two lines will be matched. Silly, you say? Wait 'til you see the *next* sentence: (If the second address is a number less than or equal to the line number first selected, only one line is selected.) Thus it is possible to match only one with two addresses; "5,5d" works as expected. But "5,4d" also deletes line 5! Since it's documented I would classify it as a "feature", however silly and unwanted it may be... I don't believe there is any work-around if you restrict yourself to sed. Using awk, you can say awk 'flag != 0; /pattern/ {flag = 1}' Kenneth Almquist houxm!hropus!ka