Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uwm.edu!zaphod.mps.ohio-state.edu!mips!bridge2!jarthur!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.unix.questions Subject: Re: a Sed question Message-ID: <6968@jpl-devvax.JPL.NASA.GOV> Date: 1 Feb 90 23:41:08 GMT References: <520@mirsa.UUCP> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 40 In article <520@mirsa.UUCP> muller@mirsa.UUCP (Christophe Muller) writes: : I wanted to find all the lines matching a : pattern, delete these lines _and_ the line immediately following. : : After half an hour of tests, man, Unix books, i gave up and used a : small awk script that worked well the first time ! I just thought that : sed might be faster, but is it possible ? Certainly. /pattern/{ N d } If pattern matches, append the next line to the current line, and then discard the whole pattern buffer. : (Note: we still don't have perl...) It doesn't buy you much in this case, depending on the pattern. Searching for /window/ in /etc/termcap, perl beats sed by only .2 seconds, less than a 20% speedup. On a more complicated pattern, you might get more. Or less. That's using the perl command: time perl -pe '<>,$_ = "" if /window/;' /etc/termcap > /dev/null 1.0u 0.1s 0:02 40% 191+162k 23+5io 7pf+0w vs time sed -f window.sed /etc/termcap >/dev/null 1.2u 0.1s 0:02 56% 29+40k 24+0io 1pf+0w where window.sed contains the appropriate commands. awk weighs in at time awk '/window/{getline;next}{print}' /etc/termcap > /dev/null 2.3u 0.1s 0:03 72% 55+112k 22+0io 4pf+0w Larry Wall lwall@jpl-devvax.jpl.nasa.gov