From debbugs-submit-bounces@debbugs.gnu.org Fri Nov 06 11:47:01 2015 Received: (at submit) by debbugs.gnu.org; 6 Nov 2015 16:47:01 +0000 Received: from localhost ([127.0.0.1]:56031 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZukAG-0001KU-Qw for submit@debbugs.gnu.org; Fri, 06 Nov 2015 11:47:01 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49058) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZujBQ-00085d-9v for submit@debbugs.gnu.org; Fri, 06 Nov 2015 10:44:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZujBP-00050o-22 for submit@debbugs.gnu.org; Fri, 06 Nov 2015 10:44:07 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:51848) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZujBO-00050k-VK for submit@debbugs.gnu.org; Fri, 06 Nov 2015 10:44:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZujBO-00074a-12 for bug-sed@gnu.org; Fri, 06 Nov 2015 10:44:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZujBN-00050S-7e for bug-sed@gnu.org; Fri, 06 Nov 2015 10:44:05 -0500 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:37653) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZujBN-00050M-1w for bug-sed@gnu.org; Fri, 06 Nov 2015 10:44:05 -0500 Received: by wmll128 with SMTP id l128so44173735wml.0 for ; Fri, 06 Nov 2015 07:44:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to:content-type; bh=LgE9MwLiZzw2Ix65Wt3KHLAxgGROWGxHdYvyJkTKPQ4=; b=ZEyTT1I9o/BN1m26SJp1icYy7NE4mi5gKy4Y2HF7uY1RYbh8t4A4Qsrxb/mXkKaaeD XbkVLYa3w4GvDAfowaiG20owIafIm7fbkoB+txDg5nIODkMZ31+0fBL2E5zZ/CtT8JFU n5J9v1BoskAo5Hskzqh6LoSRaeC/Qy1RftIcxbvQpEa/gXBpeR7Gzl2X/rRxEmzDRhFW kuaTDumOkvvfi5crA4FXm8lBgheje0c0lecb8V7uYihZYdDwMPavESLAsNbi/T3yrb7L fygcBi/kuktYO7NiTHzKQvbCdeZeNcciWsf9kVwOgIbZAL+0SF+sTRZ68+zvege0n0qm KMLg== MIME-Version: 1.0 X-Received: by 10.28.138.195 with SMTP id m186mr11501826wmd.2.1446824644222; Fri, 06 Nov 2015 07:44:04 -0800 (PST) Received: by 10.194.72.73 with HTTP; Fri, 6 Nov 2015 07:44:04 -0800 (PST) Date: Fri, 6 Nov 2015 17:44:04 +0200 X-Google-Sender-Auth: w0OIfwFM63Cfy0GmprwBPOq0EXY Message-ID: Subject: sed docs bug: No documentation of which commands must be terminated by newlines From: Ori Avtalion To: bug-sed@gnu.org Content-Type: text/plain; charset=UTF-8 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Fri, 06 Nov 2015 11:46:59 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) This report is based on the docs for 4.2.2 Section 3 says: > Some commands, due to their syntax, cannot be followed by semicolons > working as command separators and thus should be terminated with > newlines or be placed at the end of a script or script-file. I can find no mention of which commands this applies to. This limitation should be mentioned next to each such command. I'm specifically thinking of: * 'r filename' * 'R filename' * 'w filename' * 'W file-name' All of these commands use read_filename() in compile.c, which reads a filename until the end of the line/file. If I have missed any commands, these should also be documented. Related to this, a few other small issues: * The documentation for 'W' uses 'file-name' instead of 'filename'. It should be 'filename'. * The documentation for 'w filename' reference a 'file-name' in their description. It should be 'filename'. Thanks for maintaining sed! From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 24 22:52:29 2017 Received: (at 21845) by debbugs.gnu.org; 25 Jan 2017 03:52:29 +0000 Received: from localhost ([127.0.0.1]:41344 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cWEdJ-0007LW-Bl for submit@debbugs.gnu.org; Tue, 24 Jan 2017 22:52:29 -0500 Received: from mail-qk0-f196.google.com ([209.85.220.196]:34772) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cWEdH-0007LK-T9 for 21845@debbugs.gnu.org; Tue, 24 Jan 2017 22:52:28 -0500 Received: by mail-qk0-f196.google.com with SMTP id e1so8909314qkh.1 for <21845@debbugs.gnu.org>; Tue, 24 Jan 2017 19:52:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=CAATuDczJ+ouxERhmb5IcBoQ7Vq/kLvCM2SSpFe+UfY=; b=hurvRPRHluSao0jML1i87J1o+nBEiI91g7S5lEp6NBbJxi/ixqjs+QdM+RKjOZK/5o lWMyrbNwRcBsf3GYii6YB0IqYQUVgXRhgK8NEg0vnErLkogXv5GpAsul8aPVhRRlrI75 e5Czt35NSVHoK5TVf93FMVFGurrj6TKxoQGEdul7SlSDrpI4ScQUKJSaIgF9eIiTgja8 Hmqi0O71o8GO3a31IeQP2+mkfkPzqKz+9FNlyST9h8E478ZU3nNU7/k0vimqQFBUyjX6 xRZ1rKkEwtdrvd7zFvuUarR7ZoCrI5+S+GAK+/QmAen/LhLd4x6R0adIl6+CbG5pB7jS U//A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=CAATuDczJ+ouxERhmb5IcBoQ7Vq/kLvCM2SSpFe+UfY=; b=Km5bpZUhmrdPYeSUET2v5W69VvFN+TeIQ29A55gNPORhr0nD7dYFEI9OmbE5Q9fPKJ 4ULoKXPD1QCkJ99Exw0WNukHrLf69YW2l9jYqxZdwmzANPn1yslTuJfPlVcO1mlZ946y lJ0fNgVWDUROQEwLCHv3GRwDlPQRnDzRwMVPZZoFSZTga8W8Y/xSyRvzISkZdmUyeEQE NIpgT6MSUk+hyAcs+Cd/0qwjJ3F++0IUoRhnTnBi7JF/FYRSUaegwKY7SU/xatSQ8ZP0 ORafCORXKNuk4fGCm8tckA6BksrJZxJ+EKjhEj952ivvtPsfT40alZuEHTwXE1sbL0oj qfNA== X-Gm-Message-State: AIkVDXK41Klm3fkEuTxVRxmU9Ua8WMKoYxARxjCd9npHww68Id8x9QKFRa06UJIN+w53rQ== X-Received: by 10.55.153.2 with SMTP id b2mr5600015qke.314.1485316342414; Tue, 24 Jan 2017 19:52:22 -0800 (PST) Received: from gmail.com (housegordon.org. [104.236.108.240]) by smtp.gmail.com with ESMTPSA id x62sm17751184qkg.31.2017.01.24.19.52.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Jan 2017 19:52:21 -0800 (PST) Date: Wed, 25 Jan 2017 03:51:51 +0000 From: Assaf Gordon To: Ori Avtalion Subject: Re: bug#21845: sed docs bug: No documentation of which commands must be terminated by newlines Message-ID: <20170125035149.GJ9668@gmail.com> References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="IS0zKkzwUGydFO0o" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Score: -0.2 (/) X-Debbugs-Envelope-To: 21845 Cc: 21845@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.2 (/) --IS0zKkzwUGydFO0o Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Hello Ori, Sorry for the delayed response. On Fri, Nov 06, 2015 at 05:44:04PM +0200, Ori Avtalion wrote: >Some commands, due to their syntax, cannot be followed by semicolons >[...] >I can find no mention of which commands this applies to. >This limitation should be mentioned next to each such command. Thank you for mentioning this. Indeed an important piece of information. I'm considering adding a new section about this. Draft attached, comments welcomed. >The documentation uses 'file-name' instead of 'filename'. Fixed as well. regards, - assaf --IS0zKkzwUGydFO0o Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-doc-new-multiple-commands-syntax-section.patch" >From 079f3409b60782d5a4b1da678fa5831ea9c8a01f Mon Sep 17 00:00:00 2001 From: Assaf Gordon Date: Wed, 25 Jan 2017 03:41:59 +0000 Subject: [PATCH] doc: new 'multiple commands syntax' section Explain which commands can be separated by semicolon and which require newlines. Requested by Ori Avtalion in https://bugs.gnu.org/21845 . * doc/sed.texi (Multiple commands syntax): New section in "sed scripts" chapter. --- doc/sed.texi | 235 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 232 insertions(+), 3 deletions(-) diff --git a/doc/sed.texi b/doc/sed.texi index c45b150..36953a3 100644 --- a/doc/sed.texi +++ b/doc/sed.texi @@ -484,6 +484,7 @@ $ echo | sed 'Q42' ; echo $? * Other Commands:: Less frequently used commands * Programming Commands:: Commands for @command{sed} gurus * Extended Commands:: Commands specific of @value{SSED} +* Multiple commands syntax:: Extnesion for easier scripting @end menu @node sed script overview @@ -586,6 +587,7 @@ thus should be terminated with newlines or be placed at the end of a @var{script} or @var{script-file}. Commands can also be preceded with optional non-significant whitespace characters. +@xref{Multiple commands syntax}. @@ -903,12 +905,12 @@ while in general flags for the @code{s} command show their effect just once. This behavior, although documented, might change in future versions. -@item w @var{file-name} +@item w @var{filename} @cindex Text, writing to a file after substitution @cindex @value{SSEDEXT}, @file{/dev/stdout} file @cindex @value{SSEDEXT}, @file{/dev/stderr} file If the substitution was made, then write out the result to the named file. -As a @value{SSED} extension, two special values of @var{file-name} are +As a @value{SSED} extension, two special values of @var{filename} are supported: @file{/dev/stderr}, which writes the result to the standard error, and @file{/dev/stdout}, which writes to the standard output.@footnote{This is equivalent to @code{p} unless the @option{-i} @@ -1464,7 +1466,7 @@ file will then be reread and inserted on each of the addressed lines. @cindex @value{SSEDEXT}, @file{/dev/stdout} file @cindex @value{SSEDEXT}, @file{/dev/stderr} file Write the pattern space to @var{filename}. -As a @value{SSED} extension, two special values of @var{file-name} are +As a @value{SSED} extension, two special values of @var{filename} are supported: @file{/dev/stderr}, which writes the result to the standard error, and @file{/dev/stdout}, which writes to the standard output.@footnote{This is equivalent to @code{p} unless the @option{-i} @@ -1706,7 +1708,234 @@ script in most multibyte locales (including UTF-8 locales). @end table +@node Multiple commands syntax +@section Multiple commands syntax + +@c POSIX says: +@c Editing commands other than {...}, a, b, c, i, r, t, w, :, and # +@c can be followed by a , optional characters, and +@c another editing command. However, when an s editing command is used +@c with the w flag, following it with another command in this manner +@c produces undefined results. + +There are several methods to specify multiple commands in a @command{sed} +program. + +Using newlines is most natural when running sed script from a file +(using @option{-f} option). + +On the command line, all @command{sed} commands can be separated by a +newline, or with multiple @option{-e} parameters: + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 6 | sed '1d +3d +5d' +2 +4 +6 +$ seq 6 | sed -e 1d -e 3d -e 5d +2 +4 +6 +@end group +@end example +@codequoteundirected off +@codequotebacktick off + +Most simple commands can be separated by a semicolon (@samp{;}): + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 6 | sed '1d;3d;5d' +2 +4 +6 +@end group +@end example +@codequoteundirected off +@codequotebacktick off + +The @code{@{},@code{@}},@code{b},@code{t},@code{T},@code{:} commands can +be separated with a semicolon (this is a non-portable @value{SSED} extension). + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 4 | sed '@{1d;3d@}' +2 +4 + +$ seq 6 | sed '@{1d;3d@};5d' +2 +4 +6 +@end group +@end example +@codequoteundirected off +@codequotebacktick off + +Labels used in @code{b},@code{t},@code{T},@code{:} commands are read +until the semicolon. Leading and trailing whitespaces are ignored. In +the examples below the label is @samp{x}. The first example works +with @value{SSED}. The second is a portable equivalent. For more +information about branching and labels @pxref{Branching and flow +control}. + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 3 | sed '/1/b x ; s/^/=/ ; :x ; 3d' +1 +=2 + +$ seq 3 | sed -e '/1/bx' -e 's/^/=/' -e ':x' -e '3d' +1 +=2 +@end group +@end example +@codequoteundirected off +@codequotebacktick off + + + +@subsection Commands Requiring a newline + +The following commands cannot be separated by a semicolon and +require a newline: + +@table @asis + +@item @code{a},@code{c},@code{i} (append/change/insert) + +All characters following @code{a},@code{c},@code{i} commands are taken +as the text to append/change/insert. Using a semicolon leads to +undesirable results: + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 2 | sed '1aHello ; 2d' +1 +Hello ; 2d +2 +@end group +@end example +@codequoteundirected off +@codequotebacktick off + +Separate the commands using @option{-e} or a newline: + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 2 | sed -e 1aHello -e 2d +1 +Hello + +$ seq 2 | sed '1aHello +2d' +1 +Hello +@end group +@end example +@codequoteundirected off +@codequotebacktick off + +Note that specifing the text to add (@samp{Hello}) immediately +after @code{a},@code{c},@code{i} is itself a @value{SSED} extension. +A portable, POSIX-compliant alternative is: + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 2 | sed '1a\ +Hello +2d' +1 +Hello +@end group +@end example +@codequoteundirected off +@codequotebacktick off + +@item @code{#} (comment) + +All characters following @samp{#} until the next newline are ignored. + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 3 | sed '# this is a comment ; 2d' +1 +2 +3 + + +$ seq 3 | sed '# this is a comment +2d' +1 +3 +@end group +@end example +@codequoteundirected off +@codequotebacktick off + +@item @code{r},@code{R},@code{w},@code{W} (reading and writing files) + +The @code{r},@code{R},@code{w},@code{W} commands parse the filename +until end of the line. If whitespace or semicolons are found, they will +be included in the filename, leading to unexpected results: + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 2 | sed '1w hello.txt ; 2d' +1 +2 + +$ ls -log +total 4 +-rw-rw-r-- 1 2 Jan 23 23:03 hello.txt ; 2d + +$ cat 'hello.txt ; 2d' +1 +@end group +@end example +@codequoteundirected off +@codequotebacktick off + +Note that @command{sed} silently ignores read/write errors in +@code{r},@code{R},@code{w},@code{W} commands (such as missing files). +In the following example, @command{sed} tries to read a file named +@samp{@file{hello.txt ; N}}. The file is missing, and the error is silently ignored: + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ echo x | sed '1rhello.txt ; N' +x +@end group +@end example +@codequoteundirected off +@codequotebacktick off + + +@end table @node sed addresses -- 1.9.0 --IS0zKkzwUGydFO0o-- From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 24 23:35:05 2017 Received: (at 21845) by debbugs.gnu.org; 25 Jan 2017 04:35:05 +0000 Received: from localhost ([127.0.0.1]:41359 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cWFIX-0001a8-H5 for submit@debbugs.gnu.org; Tue, 24 Jan 2017 23:35:05 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:32785) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cWFIV-0001Zb-Ee for 21845@debbugs.gnu.org; Tue, 24 Jan 2017 23:35:03 -0500 Received: by mail-io0-f195.google.com with SMTP id 101so755107iom.0 for <21845@debbugs.gnu.org>; Tue, 24 Jan 2017 20:35:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=GHESLWYSKOgQXfCtT2rY9r7mTNku+e9Ss74jk6Dgzvk=; b=I6KRs6Ep9ZW9i2JDHE4hjQbI83E9cBGAEodlYpWt+w1AG2UUXu6Ugy9wq0Qswiuaor UsLYRnZyOX7JnDDyaKX+VrWpNxYvjyfZNLExilefmxgsUcWiCwNIOZO60Nkbig1DsDXp XBdO27bBF2guPdD8XVtIgfmCjdMs3YbsLS/9fsty49EwPoOKGdZMH4VRnF4GJo80EAGD iaa3P8dqiYS0e6qbIoxHMDm89zluS1MxkHBGFKypWsfPN4rdaBLAEcNwHVp7nX2oaGT8 117hJIOj9Pabg2KWPNQOsr25PO3QIyKSmpOcj2QQrnsRZTj744ZECWEf7KFMmLRXLtp+ dP4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=GHESLWYSKOgQXfCtT2rY9r7mTNku+e9Ss74jk6Dgzvk=; b=qZ9xepvmJZjh1g+7eZdkCsl5jWBSvzQaDlg/FEWPbbMWkfQQZen0WgX6W6bC0E00Mm s8lMJM/pgLuGpBOCHt2aXzLS8W7Dv0gyz0yaBNisCG2Ljy9BjTu5+E/gGPnNz/rCUpDY TkH4dH00PWwA/TSbOP3cxQ25BHteOm6aFzNF6/4iaQ0IL57V1P8PV4DCYOvnJbRWZSKU YK6XNTQAnifh/QfcopiriLXboHIjsvAKyzNyvOnCBiB2X20wN/JK0pDtJejpLU6tvJxo gc7duwQq5NI3tUdqdpV2DUjn4mYsK8ARqy+rit7Nf3Vo+gXx/xILnNIzaXKGYWn6UO4L Qn+Q== X-Gm-Message-State: AIkVDXLg5ORSTcm6/9d1Q8rDvcqUaMV5pSTBj2sBqfoaaLkHToEE6rZA5T7AQ8vvxms3usK6FrTX08SElrCrow== X-Received: by 10.107.164.18 with SMTP id n18mr32754502ioe.29.1485318897925; Tue, 24 Jan 2017 20:34:57 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.191.130 with HTTP; Tue, 24 Jan 2017 20:34:37 -0800 (PST) In-Reply-To: <20170125035149.GJ9668@gmail.com> References: <20170125035149.GJ9668@gmail.com> From: Jim Meyering Date: Tue, 24 Jan 2017 20:34:37 -0800 X-Google-Sender-Auth: yZek5ecDvdmrG9kUQnTBooYqD6M Message-ID: Subject: Re: bug#21845: sed docs bug: No documentation of which commands must be terminated by newlines To: Assaf Gordon Content-Type: multipart/mixed; boundary=001a1141bc7e4a1f580546e3c13c X-Spam-Score: -0.6 (/) X-Debbugs-Envelope-To: 21845 Cc: Ori Avtalion , 21845@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.6 (/) --001a1141bc7e4a1f580546e3c13c Content-Type: text/plain; charset=UTF-8 On Tue, Jan 24, 2017 at 7:51 PM, Assaf Gordon wrote: > Hello Ori, > > Sorry for the delayed response. > > On Fri, Nov 06, 2015 at 05:44:04PM +0200, Ori Avtalion wrote: >> >> Some commands, due to their syntax, cannot be followed by semicolons >> [...] >> I can find no mention of which commands this applies to. >> This limitation should be mentioned next to each such command. > > > Thank you for mentioning this. Indeed an important piece of information. > > I'm considering adding a new section about this. > Draft attached, comments welcomed. Thank you for that addition. I did a quick once-over and suggest these changes: --001a1141bc7e4a1f580546e3c13c Content-Type: text/x-patch; charset=US-ASCII; name="sed-0001-doc-new-multiple-commands-syntax-section-touch-up.patch" Content-Disposition: attachment; filename="sed-0001-doc-new-multiple-commands-syntax-section-touch-up.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_iycgi7sl1 ZGlmZiAtLWdpdCBhL2RvYy9zZWQudGV4aSBiL2RvYy9zZWQudGV4aQppbmRleCAzNjk1M2EzLi5l ZTNhNDRlIDEwMDY0NAotLS0gYS9kb2Mvc2VkLnRleGkKKysrIGIvZG9jL3NlZC50ZXhpCkBAIC00 ODQsNyArNDg0LDcgQEAgJCBlY2hvIHwgc2VkICdRNDInIDsgZWNobyAkPwogKiBPdGhlciBDb21t YW5kczo6ICAgICAgICAgICBMZXNzIGZyZXF1ZW50bHkgdXNlZCBjb21tYW5kcwogKiBQcm9ncmFt bWluZyBDb21tYW5kczo6ICAgICBDb21tYW5kcyBmb3IgQGNvbW1hbmR7c2VkfSBndXJ1cwogKiBF eHRlbmRlZCBDb21tYW5kczo6ICAgICAgICBDb21tYW5kcyBzcGVjaWZpYyBvZiBAdmFsdWV7U1NF RH0KLSogTXVsdGlwbGUgY29tbWFuZHMgc3ludGF4OjogRXh0bmVzaW9uIGZvciBlYXNpZXIgc2Ny aXB0aW5nCisqIE11bHRpcGxlIGNvbW1hbmRzIHN5bnRheDo6IEV4dGVuc2lvbiBmb3IgZWFzaWVy IHNjcmlwdGluZwogQGVuZCBtZW51CgogQG5vZGUgc2VkIHNjcmlwdCBvdmVydmlldwpAQCAtMTE1 MSw3ICsxMTUxLDcgQEAgaGVsbG8KIEBjb2RlcXVvdGV1bmRpcmVjdGVkIG9mZgogQGNvZGVxdW90 ZWJhY2t0aWNrIG9mZgoKLUxlYWRpbmcgd2hpdGVzcGFjZXMgYWZ0ZXIgdGhlIEBjb2Rle2F9IGNv bW1hbmQgYXJlIGlnbm9yZWQuCitMZWFkaW5nIHdoaXRlc3BhY2UgYWZ0ZXIgdGhlIEBjb2Rle2F9 I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sb25zIGFyZSBmb3VuZCwgdGhleSB3aWxsCiBiZSBpbmNs dWRlZCBpbiB0aGUgZmlsZW5hbWUsIGxlYWRpbmcgdG8gdW5leHBlY3RlZCByZXN1bHRzOgoKIEBj b2RlcXVvdGV1bmRpcmVjdGVkIG9uCg== --001a1141bc7e4a1f580546e3c13c-- From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 26 21:54:52 2017 Received: (at 21845) by debbugs.gnu.org; 27 Jan 2017 02:54:52 +0000 Received: from localhost ([127.0.0.1]:46839 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cWwgd-00059U-0a for submit@debbugs.gnu.org; Thu, 26 Jan 2017 21:54:52 -0500 Received: from mail-qt0-f193.google.com ([209.85.216.193]:33431) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cWwga-00059F-Mg for 21845@debbugs.gnu.org; Thu, 26 Jan 2017 21:54:49 -0500 Received: by mail-qt0-f193.google.com with SMTP id n13so43005338qtc.0 for <21845@debbugs.gnu.org>; Thu, 26 Jan 2017 18:54:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=S5GpnNFe1XxjbXqtrUDeBAqOA48p71zUz3uQcHCtoWk=; b=dBhJig/T7nQzHJ6HQ39uhmAeNHEuXsjCnF0G7S+nIWlfUi+3xVAf5GnIwi0UtyDTct eJNJb9TVkgflu3XIXRP7aEO8isl2Mc/9BRxwcgtdzlY+L1xUTNufNbmqMFdfrV5qHrYB oc7WUy6E39PN88lbiXaw2HWmPpPH+Y/imAzB6KzlKLSDU1CK+yDleJI14jBGAwLrSE53 yo0FpjR0zu63F9SJtBj9qDW+yyXQGhDESRjkMIuDyfrMAKzWBf1LL52lhsttrqd4Rbc7 0knsb3S1+qIHIKdLnrzwheSiHJUXnXRvhgbOkVisGC+bhxI83/UcxhcrYyNVUEbf3f3E WE2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=S5GpnNFe1XxjbXqtrUDeBAqOA48p71zUz3uQcHCtoWk=; b=AAtGa3b5ePTkjsK6E2Nbx2OYIAr9BA5aHHFoVPieStVc05fk05dshAR+Vy5/LEQpet +3fi/7O9oEDsre2UzLCWCsDnDPr0AYYn6tNhrajgOReQkkaRzUn5VeNTLBjomanb11+K bYFVIShr2AchsEXgdoQdcI3w4jDsOUv2j0YYFu+x4wu2jl2Fg9w4uqqtY/e12PaAb+mE APnxABI6/UErbig4lQ/vBenT5NofjdGgClUYrCZJFE7EzN03LeavcyWDnp9rBgPs3wXx XZwtehYqJDwg/GUoLokBfRNn3plENWFb7n6k7rs9z8SYfYaj7C/dKrCcqt2ykHvsSbmn XRhw== X-Gm-Message-State: AIkVDXJK6kmse3wV6hT7JYaQk3QNK4VDq6r0zKP+6KQibY3Qi5hbA0jVHnCkQslAFOX6sw== X-Received: by 10.200.55.230 with SMTP id e35mr5875434qtc.30.1485485683089; Thu, 26 Jan 2017 18:54:43 -0800 (PST) Received: from gmail.com (housegordon.org. [104.236.108.240]) by smtp.gmail.com with ESMTPSA id t7sm2970081qtb.11.2017.01.26.18.54.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jan 2017 18:54:42 -0800 (PST) Date: Fri, 27 Jan 2017 02:54:12 +0000 From: Assaf Gordon To: Jim Meyering Subject: Re: bug#21845: sed docs bug: No documentation of which commands must be terminated by newlines Message-ID: <20170127025411.GA12674@gmail.com> References: <20170125035149.GJ9668@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="6TrnltStXW4iwmi0" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 21845 Cc: Ori Avtalion , 21845@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) --6TrnltStXW4iwmi0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Hello Jim, On Tue, Jan 24, 2017 at 08:34:37PM -0800, Jim Meyering wrote: >On Tue, Jan 24, 2017 at 7:51 PM, Assaf Gordon wrote: >> On Fri, Nov 06, 2015 at 05:44:04PM +0200, Ori Avtalion wrote: >>> >>> Some commands, due to their syntax, cannot be followed by semicolons >> >> Thank you for mentioning this. Indeed an important piece of information. >> >> I'm considering adding a new section about this. > > I did a quick once-over and suggest these changes: Thanks for the review. I've incorporated your changes, but also added two small items (about 'e' and 's///[ew]') - so sending again before pushing anything. comments again welcomed, - assaf --6TrnltStXW4iwmi0 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-doc-new-multiple-commands-syntax-section.patch" >From 29813b297b7f8628241327215695833c60da298d Mon Sep 17 00:00:00 2001 From: Assaf Gordon Date: Wed, 25 Jan 2017 03:41:59 +0000 Subject: [PATCH] doc: new 'multiple commands syntax' section Explain which commands can be separated by semicolon and which require newlines. Requested by Ori Avtalion in https://bugs.gnu.org/21845 . * doc/sed.texi (Multiple commands syntax): New section in "sed scripts" chapter. --- doc/sed.texi | 290 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 284 insertions(+), 6 deletions(-) diff --git a/doc/sed.texi b/doc/sed.texi index 249f59c..a85f2c6 100644 --- a/doc/sed.texi +++ b/doc/sed.texi @@ -484,6 +484,7 @@ $ echo | sed 'Q42' ; echo $? * Other Commands:: Less frequently used commands * Programming Commands:: Commands for @command{sed} gurus * Extended Commands:: Commands specific of @value{SSED} +* Multiple commands syntax:: Extension for easier scripting @end menu @node sed script overview @@ -586,6 +587,7 @@ thus should be terminated with newlines or be placed at the end of a @var{script} or @var{script-file}. Commands can also be preceded with optional non-significant whitespace characters. +@xref{Multiple commands syntax}. @@ -903,12 +905,12 @@ while in general flags for the @code{s} command show their effect just once. This behavior, although documented, might change in future versions. -@item w @var{file-name} +@item w @var{filename} @cindex Text, writing to a file after substitution @cindex @value{SSEDEXT}, @file{/dev/stdout} file @cindex @value{SSEDEXT}, @file{/dev/stderr} file If the substitution was made, then write out the result to the named file. -As a @value{SSED} extension, two special values of @var{file-name} are +As a @value{SSED} extension, two special values of @var{filename} are supported: @file{/dev/stderr}, which writes the result to the standard error, and @file{/dev/stdout}, which writes to the standard output.@footnote{This is equivalent to @code{p} unless the @option{-i} @@ -1149,7 +1151,7 @@ hello @codequoteundirected off @codequotebacktick off -Leading whitespaces after the @code{a} command are ignored. +Leading whitespace after the @code{a} command is ignored. The text to add is read until the end of the line. @@ -1238,7 +1240,7 @@ hello @codequoteundirected off @codequotebacktick off -Leading whitespaces after the @code{i} command are ignored. +Leading whitespace after the @code{i} command is ignored. The text to add is read until the end of the line. @item i\ @@ -1319,7 +1321,7 @@ hello @codequoteundirected off @codequotebacktick off -Leading whitespaces after the @code{c} command are ignored. +Leading whitespace after the @code{c} command is ignored. The text to add is read until the end of the line. @item c\ @@ -1464,7 +1466,7 @@ file will then be reread and inserted on each of the addressed lines. @cindex @value{SSEDEXT}, @file{/dev/stdout} file @cindex @value{SSEDEXT}, @file{/dev/stderr} file Write the pattern space to @var{filename}. -As a @value{SSED} extension, two special values of @var{file-name} are +As a @value{SSED} extension, two special values of @var{filename} are supported: @file{/dev/stderr}, which writes the result to the standard error, and @file{/dev/stdout}, which writes to the standard output.@footnote{This is equivalent to @code{p} unless the @option{-i} @@ -1706,7 +1708,283 @@ script in most multibyte locales (including UTF-8 locales). @end table +@node Multiple commands syntax +@section Multiple commands syntax + +@c POSIX says: +@c Editing commands other than {...}, a, b, c, i, r, t, w, :, and # +@c can be followed by a , optional characters, and +@c another editing command. However, when an s editing command is used +@c with the w flag, following it with another command in this manner +@c produces undefined results. + +There are several methods to specify multiple commands in a @command{sed} +program. + +Using newlines is most natural when running a sed script from a file +(using the @option{-f} option). + +On the command line, all @command{sed} commands may be separated by newlines. +Alternatively, you may specify each command as an argument to an @option{-e} +option: + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 6 | sed '1d +3d +5d' +2 +4 +6 + +$ seq 6 | sed -e 1d -e 3d -e 5d +2 +4 +6 +@end group +@end example +@codequoteundirected off +@codequotebacktick off + +A semicolon (@samp{;}) may be used to separate most simple commands: + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 6 | sed '1d;3d;5d' +2 +4 +6 +@end group +@end example +@codequoteundirected off +@codequotebacktick off + +The @code{@{},@code{@}},@code{b},@code{t},@code{T},@code{:} commands can +be separated with a semicolon (this is a non-portable @value{SSED} extension). +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 4 | sed '@{1d;3d@}' +2 +4 + +$ seq 6 | sed '@{1d;3d@};5d' +2 +4 +6 +@end group +@end example +@codequoteundirected off +@codequotebacktick off + +Labels used in @code{b},@code{t},@code{T},@code{:} commands are read +until a semicolon. Leading and trailing whitespace is ignored. In +the examples below the label is @samp{x}. The first example works +with @value{SSED}. The second is a portable equivalent. For more +information about branching and labels @pxref{Branching and flow +control}. + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 3 | sed '/1/b x ; s/^/=/ ; :x ; 3d' +1 +=2 + +$ seq 3 | sed -e '/1/bx' -e 's/^/=/' -e ':x' -e '3d' +1 +=2 +@end group +@end example +@codequoteundirected off +@codequotebacktick off + + + +@subsection Commands Requiring a newline + +The following commands cannot be separated by a semicolon and +require a newline: + +@table @asis + +@item @code{a},@code{c},@code{i} (append/change/insert) + +All characters following @code{a},@code{c},@code{i} commands are taken +as the text to append/change/insert. Using a semicolon leads to +undesirable results: + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 2 | sed '1aHello ; 2d' +1 +Hello ; 2d +2 +@end group +@end example +@codequoteundirected off +@codequotebacktick off + +Separate the commands using @option{-e} or a newline: + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 2 | sed -e 1aHello -e 2d +1 +Hello + +$ seq 2 | sed '1aHello +2d' +1 +Hello +@end group +@end example +@codequoteundirected off +@codequotebacktick off + +Note that specifying the text to add (@samp{Hello}) immediately +after @code{a},@code{c},@code{i} is itself a @value{SSED} extension. +A portable, POSIX-compliant alternative is: + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 2 | sed '1a\ +Hello +2d' +1 +Hello +@end group +@end example +@codequoteundirected off +@codequotebacktick off + +@item @code{#} (comment) + +All characters following @samp{#} until the next newline are ignored. + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 3 | sed '# this is a comment ; 2d' +1 +2 +3 + + +$ seq 3 | sed '# this is a comment +2d' +1 +3 +@end group +@end example +@codequoteundirected off +@codequotebacktick off + +@item @code{r},@code{R},@code{w},@code{W} (reading and writing files) + +The @code{r},@code{R},@code{w},@code{W} commands parse the filename +until end of the line. If whitespace, comments or semicolons are found, +they will be included in the filename, leading to unexpected results: + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ seq 2 | sed '1w hello.txt ; 2d' +1 +2 + +$ ls -log +total 4 +-rw-rw-r-- 1 2 Jan 23 23:03 hello.txt ; 2d + +$ cat 'hello.txt ; 2d' +1 +@end group +@end example +@codequoteundirected off +@codequotebacktick off + +Note that @command{sed} silently ignores read/write errors in +@code{r},@code{R},@code{w},@code{W} commands (such as missing files). +In the following example, @command{sed} tries to read a file named +@samp{@file{hello.txt ; N}}. The file is missing, and the error is silently +ignored: + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ echo x | sed '1rhello.txt ; N' +x +@end group +@end example +@codequoteundirected off +@codequotebacktick off + +@item @code{e} (command execution) + +Any characters following the @code{e} command until the end of the line +will be sent to the shell. If whitespace, comments or semicolons are found, +they will be included in the shell command, leading to unexpected results: + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ echo a | sed '1e touch foo#bar' +a + +$ ls -1 +foo#bar + +$ echo a | sed '1e touch foo ; s/a/b/' +sh: 1: s/a/b/: not found +a +@end group +@end example +@codequoteundirected off +@codequotebacktick off + + +@item @code{s///[we]} (substitute with @code{e} or @code{w} flags) + +In a substitution command, the @code{w} flag writes the substitution +result to a file and the @code{e} flag executes the subsitution result +as a shell command. Similarly to the @code{r/R/w/W/e} commands, these +must be terminated with a newline. If whitespace, comments or semicolons +are found, they will be included in the shell command ro filename, leading to +unexpected results: + +@codequoteundirected on +@codequotebacktick on +@example +@group +$ echo a | sed 's/a/b/w1.txt#foo' +b + +$ ls -1 +1.txt#foo +@end group +@end example +@codequoteundirected off +@codequotebacktick off + +@end table @node sed addresses -- 1.9.0 --6TrnltStXW4iwmi0-- From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 27 00:30:23 2017 Received: (at 21845) by debbugs.gnu.org; 27 Jan 2017 05:30:23 +0000 Received: from localhost ([127.0.0.1]:46853 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cWz79-0000J7-Gf for submit@debbugs.gnu.org; Fri, 27 Jan 2017 00:30:23 -0500 Received: from mail-it0-f66.google.com ([209.85.214.66]:34173) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cWz77-0000Iu-VQ for 21845@debbugs.gnu.org; Fri, 27 Jan 2017 00:30:22 -0500 Received: by mail-it0-f66.google.com with SMTP id o185so7337271itb.1 for <21845@debbugs.gnu.org>; Thu, 26 Jan 2017 21:30:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=YLNQdwnF8kkshx22IQH9D7mhHMwlEX54e1Ab9ezlcU8=; b=bMiPXytF62IhNUZbVMfqlN6ltM3lO5Nj75Jl/pBbwe/85YV09GoUdUktOqeUePEaHj nMIlW7ffv9mEzovL4Ne24wz05CQPhkFWBlEEHgdZOLGFWbo7gYp42A7VAlvJDDaD3MA5 DbPTmLtq/Lr8aBydG/OsmXjkCK8BNbAdy4i4oVTAMXhzzPwWWD2BdH3BgNky8NMfLvRM ZJl1LB58AgJiEAeX8bllM/QYYnD0U63WNxTa/Q4UpDjNVUhXmX93ZtzGHG6FIqrRSdqs JgwCg+npNxWuPjy5zk+/j/IeGVUIziezGYIn4kuu+BaR/PUu5CZcBJRv+0ePmB4sqcbE Rk+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=YLNQdwnF8kkshx22IQH9D7mhHMwlEX54e1Ab9ezlcU8=; b=XbthE/Ju/k2s61zsqtMhQlCDCnAaVoniKKNBNqNP3PIU5EdWw0rLZCeC4DhhWEIamX YzppFBzJqWukwn5PJDkthpf5ILWshPb7jRmX5BSbnxCWQlPxHT+vTh/XNAdW/MCOOtQV tNEK1o7L+i777Rh5Ql7aEuBrvrTQSjFu6IF371EYXfObMYJJ8K6Y2oDOhGCRPhxQN0Vs aIu5PlaaIx8NKZSlWWxQqp/T/lfr4mzPlPOliXpVHCAX0OevZq4PVzEJwafEGpmWh6VW k75BUEUzW06afXL8VQCEN8mCcW6kH4ElI83PS5C2vIxeOI3qF01A6OhC/byGS3A9iL2Y GKDQ== X-Gm-Message-State: AIkVDXKwOUP6FI6MaA0geprIG/Oop2rFlXDvD65fDHR1CmLZSjV4gQ95jnEYi3EiC3BhAJJsKCDUu+XKdH/L0Q== X-Received: by 10.36.112.206 with SMTP id f197mr1862687itc.31.1485495016222; Thu, 26 Jan 2017 21:30:16 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.191.130 with HTTP; Thu, 26 Jan 2017 21:29:55 -0800 (PST) In-Reply-To: <20170127025411.GA12674@gmail.com> References: <20170125035149.GJ9668@gmail.com> <20170127025411.GA12674@gmail.com> From: Jim Meyering Date: Thu, 26 Jan 2017 21:29:55 -0800 X-Google-Sender-Auth: cdAzUbOUeIcDP_6dxS7JhkA868o Message-ID: Subject: Re: bug#21845: sed docs bug: No documentation of which commands must be terminated by newlines To: Assaf Gordon Content-Type: multipart/mixed; boundary=001a113f76b8c26e1d05470cc2c4 X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 21845 Cc: Ori Avtalion , 21845@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) --001a113f76b8c26e1d05470cc2c4 Content-Type: text/plain; charset=UTF-8 On Thu, Jan 26, 2017 at 6:54 PM, Assaf Gordon wrote: > Hello Jim, > > On Tue, Jan 24, 2017 at 08:34:37PM -0800, Jim Meyering wrote: >> >> On Tue, Jan 24, 2017 at 7:51 PM, Assaf Gordon >> wrote: >>> >>> On Fri, Nov 06, 2015 at 05:44:04PM +0200, Ori Avtalion wrote: >>>> >>>> >>>> Some commands, due to their syntax, cannot be followed by semicolons >>> >>> >>> Thank you for mentioning this. Indeed an important piece of information. >>> >>> I'm considering adding a new section about this. >> >> >> I did a quick once-over and suggest these changes: > > > Thanks for the review. > I've incorporated your changes, but also added two small items > (about 'e' and 's///[ew]') - so sending again before pushing anything. Thanks. That looks fine. One fix: s/ro/or/ and a suggested wording change: --001a113f76b8c26e1d05470cc2c4 Content-Type: application/octet-stream; name="sed-0001-doc-new-multiple-commands-syntax-section-touch-up2.patch" Content-Disposition: attachment; filename="sed-0001-doc-new-multiple-commands-syntax-section-touch-up2.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_iyfdd39v1 ZGlmZiAtLWdpdCBhL2RvYy9zZWQudGV4aSBiL2RvYy9zZWQudGV4aQ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jdGVkIG9uCg== --001a113f76b8c26e1d05470cc2c4-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jan 28 15:27:01 2017 Received: (at 21845) by debbugs.gnu.org; 28 Jan 2017 20:27:01 +0000 Received: from localhost ([127.0.0.1]:49431 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXZaP-0000Rl-8f for submit@debbugs.gnu.org; Sat, 28 Jan 2017 15:27:01 -0500 Received: from mail-qk0-f196.google.com ([209.85.220.196]:35522) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXZaN-0000RR-Fj; Sat, 28 Jan 2017 15:26:59 -0500 Received: by mail-qk0-f196.google.com with SMTP id u25so13557647qki.2; Sat, 28 Jan 2017 12:26:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=CwnEoQo6DPsadk7vEUUSfbV2G5hd1EMNLlytuT59NYI=; b=tJGGREAzTI6531utL3l2mOk95lGE1OxbCHrP+hmmBrPN2jF8K62kxlhz1F+aBQAQEd B62FEqdVLeVlf3p4obkPpqbaXarq8A+oaoy2H+tOCIbOotw4Ti3TMLGVm/RT8Ia9OCnE CKEdOOv7V5xQsDuPJJSfPDX2aVomfWxSc10fTYlTlwzg7e8q8bAOzE+UedFAF4xh6p/q SlNMmSR+t5dXTCTi7RLyUJvZUN/hlSQA4u3TUv6YsKHrRCeW6NODST7hsImRIjIS2O9u TT/4iw72UTHB2G66mFdzRg3fM38skdLY4HIhi2NgQ7YugTWGDOd/BmTLVex1at+fDgjC zOKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=CwnEoQo6DPsadk7vEUUSfbV2G5hd1EMNLlytuT59NYI=; b=hsa8bMNYx83UEJDGC2LrhPUzCv7sBPLtq8BlMcfCvhlAGgYiUgwdceLjujDsTGDuE6 rkyhDPReY9oh6CVccO8BI9AIwDEOsiooUk89OCHJP94d9r3DgU6ehoKqG01hES5GsW7R IXUko+Kffxplc1UUy17n25/D/4oZ1SiJRh9El4NgUGw1t9jwH7I34dax6HZbWVNEXDne /b5bBuVIlyE14Ow/9QnuJ3BLnm5jnsiLPlkpNiqYBhRSIZDKtkXRzwCCjhGYXqPJRgU3 pRA9cHUTL6hQC8Umx40aBczB8p59Pi5FB7BzYnGwqO4R0C6JXg4evYUZYpa/f/wW6BKP nDkw== X-Gm-Message-State: AIkVDXIVT4RKhVTnL+D+MXJcbrHK7VMd4YZd2p43VwOo2RXVveyQurdRjpWUW/0Jvc0XkQ== X-Received: by 10.55.43.149 with SMTP id r21mr15505479qkr.123.1485635214003; Sat, 28 Jan 2017 12:26:54 -0800 (PST) Received: from gmail.com (housegordon.org. [104.236.108.240]) by smtp.gmail.com with ESMTPSA id t67sm7450004qkd.41.2017.01.28.12.26.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jan 2017 12:26:53 -0800 (PST) Date: Sat, 28 Jan 2017 20:26:23 +0000 From: Assaf Gordon To: Jim Meyering Subject: Re: bug#21845: sed docs bug: No documentation of which commands must be terminated by newlines Message-ID: <20170128202622.GA8951@gmail.com> References: <20170125035149.GJ9668@gmail.com> <20170127025411.GA12674@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Score: -0.2 (/) X-Debbugs-Envelope-To: 21845 Cc: Ori Avtalion , 21845@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.2 (/) tags 21845 fixed close 21845 stop On Thu, Jan 26, 2017 at 09:29:55PM -0800, Jim Meyering wrote: >Thanks. That looks fine. One fix: s/ro/or/ and a suggested wording change: Thanks for the quick review. Pushed here: http://git.savannah.gnu.org/cgit/sed.git/commit/?id=cca9795a716e558c21 regards, - assaf From unknown Tue Aug 19 05:08:31 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 26 Feb 2017 12:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator