Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site ptsfa.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!umcp-cs!gymble!lll-crg!dual!ptsfa!dsp
From: dsp@ptsfa.UUCP (David St. Pierre)
Newsgroups: net.unix-wizards
Subject: Is this a sed BUG or a FEATURE?
Message-ID: <730@ptsfa.UUCP>
Date: Fri, 12-Jul-85 01:06:11 EDT
Article-I.D.: ptsfa.730
Posted: Fri Jul 12 01:06:11 1985
Date-Received: Sat, 13-Jul-85 14:06:28 EDT
Distribution: net
Organization: Pacific Bell, San Francisco
Lines: 52

Summary: sed 'p' function not consistent with s's 'p' flag on SV_R2 - 3B20

I was looking at Larry Wall's "newsgroups" to find out why it wasn't
reporting on newsgroups which were still in my .newsrc but unsubscribed.
After some testing I found that, in this particular context,

	-e s/aaa/bbb/ -e /bbb/p		and -e s/aaa/bbb/p

were not equivalent. Larry's sed scripts appear at the end of the article:
both of them were terminated with a  "-e d" function. Further testing
revealed

	sed -e s/aaa//bbb/ -e /bbb/p -e d
	sed -n -e s/aaa/bbb/ -e /bbb/p -e d
	sed -n -e s/aaa/bbb/ -e /bbb/p
	sed -n -e s/aaa/bbb/p -e d
	sed -n -e s/aaa/bbb/p

produced similar results, but

	sed -e s/aaa/bbb/p -e d

would produce nothing. The manual page says that the 'p' function will
"copy the pattern space to the standard output", while the 'p' flag
"prints the pattern space if a replacement was made".
I thought I understood the normal usage of the 'p' flag, but is the
wording a subtle indication that the above example is in fact a feature?

How does this example work on other systems?

Also, is the "-n" flag a standard feature of sed? I thought it should be
equivalent to a "-e d" as a final command string in all cases.

=========================
abbreviated "newsgroups"

cat $dotdir/.newsrc $dotdir/.newsrc $active | \
sed	-e '/^options/d' \
	-e '/^[	 ]/d' \
	-e '/^control/d' \
	-e '/^to\./d' \
	-e 's/^\([^ !:]*\)[ !:].*$/\1/' \
	-e "/.*$1/p" \
	-e 'd' | \
sort | uniq -u | $pager

sed < $dotdir/.newsrc \
	-e "/$1.*!/"'s/^\([^!]*\)!.*$/\1/p' \
	-e 'd' | \
sort | $pager
-- 
David St. Pierre		{ihnp4,dual,qantel}!ptsfa!dsp