need help with sed "pattern space"
chris ross
watcher at athena.mit.edu
Tue Jul 11 15:19:10 AEST 1989
hi. Got a few questions for you sed sharks...
sed claims that it "cyclically copies a line of input into a pattern space
(unless there is something left after a D command), applies in sequence all
commands whose addresses select that pattern space, and at the end of the
script copies the pattern space to the standard output (except under -n)
and deletes the pattern space"
1. Given the above description, and reading from stdin, why do simple
scripts like "sed s/a/b/g" not produce output until the _second_ input
line has been entered?
2. It seems to me that a script like "sed '/foo/,/bar/ d'" needs to retain
the pattern space for an arbitrary number of input lines. Does the phrase
"start the next cycle" in the d command documentation mean "start the next
cycle NOW, without checking other addresses, doing output, or clearing the
pattern space?" If not, why doesn't a p command after the d command print
the growing pattern space as many times as there are lines retained by
/foo/,/bar/ ?
3. Why doesn't "sed '/^$/,/^$/ D'" (note UPPERcase D) convert multiple
consecutive blank lines to a single blank line?
Obviously, I'm thinking about the pattern space in the wrong way.
Can anyone point me in the right direction?
thanx
_____________________________________
chris ross <0> watcher at athena.mit.edu
More information about the Comp.unix.questions
mailing list