| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
On 2015-05-07 20:22, [email protected] [sed-users] wrote:
> Concerning q (lower), the GNU sed manual says: Exit sed without
> processing any more commands or input. Note that the current
> pattern space is printed if auto-print is not disabled with the -n
> options.
>
> Concerning Q (upper), it says: This command is the same as q, but
> will not print the contents of pattern space.
Just for the record, I believe that "Q" is a GNU extension. Testing
on FreeBSD and OpenBSD shows it doesn't support "Q". Also, GNU's
"az" or "ix" syntax are an extension which should be written
as
sed -e 'i\
x' -e 'a\
z' -q
if you're taking portability into consideration.
> $ echo y | sed -e ix -e az -e q
> x
> y
> z
>
> $ echo y | sed -e ix -e az -e Q
> x
>
> q prints scheduled text (in this case, from a). Q does not. So the
> documentation seems incorrect, or at least incomplete. I would
> suggest q might say something like "Note that the current pattern
> space is printed if auto-print is not disabled with the -n options.
> Also, scheduled text is printed." and Q "This command is the same
> as q, but will not print the contents of pattern space, nor any
> scheduled text." Is original definition better, expanded
> definition, or something else? Any other comments?
The documentation ("info sed" for GNU's annoying info(1)
documentation instead of proper man-page documentation</rant>) does
detail that "a" enqueues for future printing, while "i" prints
immediately:
`a\'
`TEXT'
Queue the lines of text which follow this command (each but the
last ending with a `\', which are removed from the output) to be
output at the end of the current cycle, or when the next input
line is read.
`i\'
`TEXT'
Immediately output the lines of text which follow this command
(each but the last ending with a `\', which are removed from the
output).
So I would expect the behavior you see: "i" immediately outputs the
"x", then the "Q" interrupts the printing of the "y" from stdin, and
the "z" from the "a" command.
> Also, it seems Q is the only way to suppress scheduled output (from
> arR). Is that correct?
Well, that and simply refraining from scheduling output that you
don't want. Sounds like the old
Patient: Doctor, it hurts when I press here!
Doctor: Well, don't press there.
only with
User: I can't suppress scheduled output unless I use Q!
Sed: Well, don't schedule output.
:-)
-tkc