Is this a sed BUG or a FEATURE?

David St. Pierre dsp at ptsfa.UUCP
Fri Jul 12 15:06:11 AEST 1985


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



More information about the Comp.unix.wizards mailing list