a Sed question

Randal Schwartz merlyn at iwarp.intel.com
Fri Feb 2 09:49:44 AEST 1990


In article <520 at mirsa.UUCP>, muller at mirsa (Christophe Muller) writes:
| That might be a stupid question, but does somebody know how to 
| do that job with "sed" ? 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 ? (Note: we still don't have
| perl...)

Foreseeing a possible reply involving Perl means you've been following
c.u.q for a while.  Well, here's a sed solution:

sed '/pattern/{N
d
}' <<EOF
foo
bar
pattern
bletch
biz
EOF

prints 'foo' 'bar' and 'biz'.  That should be a start.  The important
thing to remember is that 'd' makes you lose control of the current
line, and the next line is restarted at the top of your script.  So,
get all your stuff together, and then do your 'd'.

Just another sed hacker (when I'm not hacking Perl),
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn at iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/



More information about the Comp.unix.questions mailing list