From unknown Fri Sep 19 23:53:49 2025 X-Loop: help-debbugs@gnu.org Subject: bug#28140: Here is a possible bug in documentation for 4.4 Resent-From: bamber ward Original-Sender: "Debbugs-submit" Resent-CC: bug-sed@gnu.org Resent-Date: Fri, 18 Aug 2017 15:35:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 28140 X-GNU-PR-Package: sed X-GNU-PR-Keywords: To: 28140@debbugs.gnu.org X-Debbugs-Original-To: bug-sed@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.150307046526375 (code B ref -1); Fri, 18 Aug 2017 15:35:01 +0000 Received: (at submit) by debbugs.gnu.org; 18 Aug 2017 15:34:25 +0000 Received: from localhost ([127.0.0.1]:44529 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dijI1-0006rK-HW for submit@debbugs.gnu.org; Fri, 18 Aug 2017 11:34:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:56571) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dijI0-0006r3-8c for submit@debbugs.gnu.org; Fri, 18 Aug 2017 11:34:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dijHu-00006s-4w for submit@debbugs.gnu.org; Fri, 18 Aug 2017 11:34:19 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=BAYES_50, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:36593) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dijHu-00006l-2D for submit@debbugs.gnu.org; Fri, 18 Aug 2017 11:34:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dijHs-0003Ix-OI for bug-sed@gnu.org; Fri, 18 Aug 2017 11:34:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dijHs-00005a-1Q for bug-sed@gnu.org; Fri, 18 Aug 2017 11:34:16 -0400 Received: from mail-qt0-x22b.google.com ([2607:f8b0:400d:c0d::22b]:37894) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dijHr-0008WU-Tk for bug-sed@gnu.org; Fri, 18 Aug 2017 11:34:15 -0400 Received: by mail-qt0-x22b.google.com with SMTP id t37so55458678qtg.5 for ; Fri, 18 Aug 2017 08:34:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=5lsBYSLpFElcYkdFqA5uP9RU/zDeTSURZ1K8vro3Hlk=; b=UMEDvg6xvnU3/tyyKCTm+F2zEuJr3JvQ6VcMVTdrn6c3BYAW3LmWyBvjkgp/YKvyDJ fHgiAslBaWG21ylu+5diwDRcm5gK2UQyNlZFLCeSVNnGtc1dQE097guMoEgVd7FS7ByT 18St0j1I3EqjTUqYXLtq63Q++sU5FN2GJ7IStXPlj0P/imiy6d0CApj3SEeCu2BDtd7O pfe778YdHFCcn9Dpkt3bpXSTLLmKJFme4o24s2qs8NvuyTR5gIUxTTFm6DnhgCyH+tJb 43xTkv7oBrVmwQhIEqEID2O8UtRPeT6rJbl3RzGO690EYyEu/UTcaENPyzWbPGJt7h18 L7gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=5lsBYSLpFElcYkdFqA5uP9RU/zDeTSURZ1K8vro3Hlk=; b=gAKTwqEK5/STEfvHtjscg1BaDEC/XMbmxobG3gfTWIR4or6Ll3qtywwDT4zx1BJTYb eaT8RxY6GihiRppEODLX+UTr4Ia84F57oFWilcw2mPCy75xSoZWlLQEmrzxSASfDTcVx Dyfj0la6Q37htsn1h53Kdv1QA4znjisnoA+lvzwI20WPWu5vQqLvAJqu66LBueJHvJ90 iXi44Qzl7pgVThza/YblvoINCX8Uas0l/tKw+z3nL4VxFmmYZQfb1A3wYfFOYNjftbRU jRImFFLn/6gxsFXCI5oW9zShvYHjhWdNkxReU6GOtdg4D2If3PiMxWXOyvNmJb1YPFQV 0e5g== X-Gm-Message-State: AHYfb5iS3WnJzQKU4GJnFULf4DC5RMzjkrCCGPYNJm+3208kye6qoXvA c52AwV3kcVHvYEa1tmvsROueQCJelIsBQMs= X-Received: by 10.200.15.84 with SMTP id l20mr6837039qtk.38.1503070453686; Fri, 18 Aug 2017 08:34:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.209.252 with HTTP; Fri, 18 Aug 2017 08:34:13 -0700 (PDT) From: bamber ward Date: Fri, 18 Aug 2017 16:34:13 +0100 Message-ID: Content-Type: multipart/alternative; boundary="001a114e729276e62e055708dcc7" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -3.8 (---) 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: -3.8 (---) --001a114e729276e62e055708dcc7 Content-Type: text/plain; charset="UTF-8" manual 4.4 section 7-8 sed -E ':x {N ; s/\n/ /g ; s/(.{40,40})/\1\n/ ; /\n/!bx ; P ;D}' does not work as described. Change line length , say to 5 sed -E ':x {N ; s/\n/ /g ; s/(.{5,5})/\1\n/ ; /\n/!bx ; P ;D}' cat line_wrap_input : apple grape pear peach pomengranate ~/sed/code-> sed -E ':x {N ; s/\n/ /g ; s/(.{5,5})/\1\n/ ; /\n/!bx ; P ; D}' \ line_wrap_input apple grap e pear peach pomengranate ~/sed/code-> This seems to work: #!/bin/sed -rf # line_wrap.sed ( :x { N s/\n/ /g :y s_(.{40,40})_\1\n_ /.{40,40}/ P s/.*\n// ty /\n/!bx } Best Wishes David L Ward --001a114e729276e62e055708dcc7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
manual 4.4
section 7-8
=C2=A0sed -E ':= x {N ; s/\n/ /g ; s/(.{40,40})/\1\n/ ; /\n/!bx ; P ;D}'
does not wor= k as described. Change line length , say to 5
=C2=A0 sed -E ':x {N ;= s/\n/ /g ; s/(.{5,5})/\1\n/ ; /\n/!bx ; P ;D}'=C2=A0
cat line_wrap= _input :
apple grape
pear peach
pomengranate

~/sed/code->= ; sed -E ':x {N ; s/\n/ /g ; s/(.{5,5})/\1\n/ ; /\n/!bx ; P ; D}' \= =C2=A0 line_wrap_input
apple
=C2=A0grap
e pear peach pomengranate<= br>

~/sed/code->

This seems to work:

#!/bin/sed -r= f
# line_wrap.sed (

:x
{
=C2=A0=C2=A0 N
=C2=A0=C2=A0 s= /\n/ /g
=C2=A0=C2=A0 :y
=C2=A0=C2=A0 s_(.{40,40})_\1\n_
=C2=A0=C2= =A0=C2=A0 /.{40,40}/=C2=A0 P
=C2=A0=C2=A0 s/.*\n//
=C2=A0=C2=A0 ty=C2=A0=C2=A0 /\n/!bx
=C2=A0=C2=A0
}

Best Wishes
<= /div>David L Ward
--001a114e729276e62e055708dcc7-- From unknown Fri Sep 19 23:53:49 2025 X-Loop: help-debbugs@gnu.org Subject: bug#28140: Here is a possible bug in documentation for 4.4 Resent-From: Assaf Gordon Original-Sender: "Debbugs-submit" Resent-CC: bug-sed@gnu.org Resent-Date: Fri, 25 Aug 2017 15:43:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28140 X-GNU-PR-Package: sed X-GNU-PR-Keywords: To: bamber ward , 28140@debbugs.gnu.org Received: via spool by 28140-submit@debbugs.gnu.org id=B28140.150367574416690 (code B ref 28140); Fri, 25 Aug 2017 15:43:01 +0000 Received: (at 28140) by debbugs.gnu.org; 25 Aug 2017 15:42:24 +0000 Received: from localhost ([127.0.0.1]:54678 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dlGka-0004L8-Dk for submit@debbugs.gnu.org; Fri, 25 Aug 2017 11:42:24 -0400 Received: from mail-it0-f43.google.com ([209.85.214.43]:35843) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dlGkY-0004Kq-6r for 28140@debbugs.gnu.org; Fri, 25 Aug 2017 11:42:22 -0400 Received: by mail-it0-f43.google.com with SMTP id o132so723958itc.1 for <28140@debbugs.gnu.org>; Fri, 25 Aug 2017 08:42:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=35Pqn6UC2Pd3ojV/9Zt5wSt61oZ7NIhBDB5jYEMhJ2s=; b=ODSEXjbmsKc8mED4Q5RVQZASq/4/MGrvydl+ZZS399GeN9UGdyHG44tc8u65GRDVfM P8WEtVhzhWUkiUelzg2ipvb67btYuJQxbp6tV3BkEEhKP080kJQgYTvMUaTe6jIReqzB 33qg/rR8EHlnCrNh+ik3qYZLBfLNUwgpZXOnkGj04vEqPObAVgBhyNhlcKz2305RO4bW NyzLG94y6AbRH/sruFuW+SbgQdYaUf7rvZhmaWCDFngcf+TzEjmGOTAmL2RGeu0Thkr9 70X41kwD7W3AShHpWvPO4Abs4HFpWmPyLani6mT8ShYHSCChIdXiCkrCAtCp0ejE6/aA 5JOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=35Pqn6UC2Pd3ojV/9Zt5wSt61oZ7NIhBDB5jYEMhJ2s=; b=k0C/YyIhNPoNahgQIb5FLf0gsVFeMRfcAh4zUPLfQHib7ZgFbxtozK1fVdWuqJXp6W 4mrx37SKmj2zQnSOu0QHc2eCnDzw5ROy+EnJF1qv9PSdXDc+k/wDD4f0zdiUhlR9qBN9 ndb7zeh9rFpnlXt61BhqU44+0iMoZ2snRos0veYGOWTSokWrgKxMwDuAi2ldAtEhkPzO kDHrnJrtmCoYyy5jr/V0koqHRs3h2zPN82dDFdZ16NiX9F+zZrbr+OJPh8sxJx8qkZ8e UyvqnH5rMVlhvEqQmHqigaNdvn7VFSly2ZuxzYhLImhiskS/3ayvXNX8N9z9WRoGmCP8 XbTQ== X-Gm-Message-State: AHYfb5jRINBNq6hK1dQFrsuBCOWdQORdgCBS7kCrADPo/jG4EmLzOy3L UpB6zW86OqV03N8x6UM= X-Received: by 10.36.181.6 with SMTP id v6mr1517774ite.49.1503675736470; Fri, 25 Aug 2017 08:42:16 -0700 (PDT) Received: from [192.168.88.239] (moose.housegordon.com. [184.68.105.38]) by smtp.gmail.com with ESMTPSA id x87sm832507ita.36.2017.08.25.08.42.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Aug 2017 08:42:15 -0700 (PDT) References: From: Assaf Gordon Message-ID: <3e62a42a-d901-bc99-b0ee-bdd5dfab61f3@gmail.com> Date: Fri, 25 Aug 2017 09:42:32 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: 0.5 (/) 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 (/) Hello, On 18/08/17 09:34 AM, bamber ward wrote: > manual 4.4 > section 7-8 > sed -E ':x {N ; s/\n/ /g ; s/(.{40,40})/\1\n/ ; /\n/!bx ; P ;D}' > does not work as described. Thank you for reporting this. Indeed, the sed program does not wrap the last line ('D' does not provide a way to loop over the last line in case it's longer than 40 characters). > #!/bin/sed -rf > # line_wrap.sed ( > > :x > { > N > s/\n/ /g > :y > s_(.{40,40})_\1\n_ > /.{40,40}/ P > s/.*\n// > ty > /\n/!bx > > } I wonder if the following program would suffice (very similar to yours, but without conditional P, just to simplify the example code in the manual). sed -E ':x { N s/\n/ /g :y s/(.{20,20})/\1\n/ /\n/!bx P s/.*\n// ty }' regards, - assaf From unknown Fri Sep 19 23:53:49 2025 X-Loop: help-debbugs@gnu.org Subject: bug#28140: Here is a possible bug in documentation for 4.4 Resent-From: Assaf Gordon Original-Sender: "Debbugs-submit" Resent-CC: bug-sed@gnu.org Resent-Date: Thu, 12 Oct 2017 06:32:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28140 X-GNU-PR-Package: sed X-GNU-PR-Keywords: To: bamber ward , 28140@debbugs.gnu.org Received: via spool by 28140-submit@debbugs.gnu.org id=B28140.150778988511726 (code B ref 28140); Thu, 12 Oct 2017 06:32:01 +0000 Received: (at 28140) by debbugs.gnu.org; 12 Oct 2017 06:31:25 +0000 Received: from localhost ([127.0.0.1]:34780 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2X1g-000333-PK for submit@debbugs.gnu.org; Thu, 12 Oct 2017 02:31:25 -0400 Received: from mail-it0-f42.google.com ([209.85.214.42]:51823) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2X1e-00032p-L0 for 28140@debbugs.gnu.org; Thu, 12 Oct 2017 02:31:23 -0400 Received: by mail-it0-f42.google.com with SMTP id o135so5647199itb.0 for <28140@debbugs.gnu.org>; Wed, 11 Oct 2017 23:31:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:references:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=fHMbTME604acrgp4UlAEWBWG9JHDalJLTGE2vGCD7EE=; b=P4FgzF9+1L/E5ECRQukUIx/wWgQyVZGXq1slacBZXa7vuYPymCnIJB4eLU4hAvKgdY UKQEeWhebJQu7C3nw1Y9rlN0E0q9NawCDuGkO+8HHpDlYd5lHqri0V/1bnlc2+RGiEc+ MeqdfFSBtYV05tXPTFXefPS8ncVJ2U9CSz2Ot8/YL8QADzAG7D21LfvT0EqMB5OzXJkL JB0FTIX6olACT9d1sS+7NnpCAihPHQSOeYUawYTeg8Kp5G25UpwfaG8Bt0vaoK2M2i0m qadN5CetdOXzhJsin0XRz7F3QJKQcK15u4xYQ0yMcGl6oMdbxsoK599c4VQPgzqjhKpv aFyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=fHMbTME604acrgp4UlAEWBWG9JHDalJLTGE2vGCD7EE=; b=d0G53z1KE4ZZ8i0FQdLhMAerClRMk+jo8cBv3omaXYRbCgF8+A6CV4Cuzr57o7U0Uw YCotsJu+1Rt8irzQYIXPmiDwvSO7IN6bbR/EzzzSx0U1Hdukw5qQDX+pepUy6Gyq7vI3 +dQn9JQHJFXxWJ2dYwYYBH/+ebdKA0qQdue1JrPCoMc8Ms++6HRrFCuDI7lSGb5qloDE xeiKkjD8HQY8D5J7kZEPU/n+MNSA9Yjz58vh5HEu6GFXXbSaWk0TapLbufK851I3lHCo sntZmmXO5iWc7R1l9k7rtxStNlYmAM5SvhiZbSKsMG4BADG+C00H5etk8xABYHzTlYOf 9pYA== X-Gm-Message-State: AMCzsaVEnkmdIMdlseimYtxMHraXbWqyvanmBX2ikWJGSotJ6Ri/VkpO /v/b3XdriJ23Q2qAZkHXoZP9lMnY X-Google-Smtp-Source: AOwi7QD6lADvqzSSzB1X631VHcEmLafw7xnU/XsKNu36jTCPMga36wfzl81eL5TGKdz1AfRvnhcHYg== X-Received: by 10.36.194.193 with SMTP id i184mr1756348itg.139.1507789876641; Wed, 11 Oct 2017 23:31:16 -0700 (PDT) Received: from [192.168.88.239] (moose.housegordon.com. [184.68.105.38]) by smtp.googlemail.com with ESMTPSA id k76sm6866350ita.4.2017.10.11.23.31.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Oct 2017 23:31:15 -0700 (PDT) From: Assaf Gordon References: <3e62a42a-d901-bc99-b0ee-bdd5dfab61f3@gmail.com> Message-ID: Date: Thu, 12 Oct 2017 00:31:14 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <3e62a42a-d901-bc99-b0ee-bdd5dfab61f3@gmail.com> Content-Type: multipart/mixed; boundary="------------6F0A7B5A42BC0B6287E76B53" Content-Language: en-US X-Spam-Score: 0.5 (/) 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 (/) This is a multi-part message in MIME format. --------------6F0A7B5A42BC0B6287E76B53 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Hello, > On 18/08/17 09:34 AM, bamber ward wrote: >> manual 4.4 >> section 7-8 >> sed -E ':x {N ; s/\n/ /g ; s/(.{40,40})/\1\n/ ; /\n/!bx ; P ;D}' >> does not work as described. I'm thinking of the attached patch, which replaces the overly terse (and incorrect) example with a longer version with better comments. Also removed second example to simplify the section. Comments very welcomed, - assaf --------------6F0A7B5A42BC0B6287E76B53 Content-Type: text/x-patch; name="0001-doc-fix-incorrect-line-wrapping-example.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-doc-fix-incorrect-line-wrapping-example.patch" >From f6dde86126f8c4f9f2c6f555e9af0aa78deec914 Mon Sep 17 00:00:00 2001 From: Assaf Gordon Date: Thu, 12 Oct 2017 00:26:14 -0600 Subject: [PATCH] doc: fix incorrect line-wrapping example Reported by Bamber Ward in https://bugs.gnu.org/28140 . * doc/sed.texi (Line length adjustment): Fix sed script; Rewrite example to long script with inlined comments; Remove second example. --- doc/sed.texi | 90 +++++++++++++++++++++++++++++------------------------------- 1 file changed, 43 insertions(+), 47 deletions(-) diff --git a/doc/sed.texi b/doc/sed.texi index cc47b66..c80bf1f 100644 --- a/doc/sed.texi +++ b/doc/sed.texi @@ -4698,7 +4698,7 @@ consecutive words spanning multiple lines, and the @code{b} command for branching. @xref{Multiline techniques} and @ref{Branching and flow control}. -These (somewhat contrived) examples deal with formatting and wrapping +This (somewhat contrived) example deal with formatting and wrapping lines of text of the following input file: @example @@ -4715,70 +4715,66 @@ of foolishness, @end group @end example -The following command will wrap lines at 40 characters: +@exdent The following sed program wraps lines at 40 characters: @codequoteundirected on @codequotebacktick on @example @group -$ sed -E ':x @{N ; s/\n/ /g ; s/(.@{40,40@})/\1\n/ ; /\n/!bx ; P ; D@}' \ - two-cities-mix.txt -It was the best of times, it was the wor -st of times, it was the age of wisdom, i -t was the age of foolishness, +$ cat wrap40.sed +# outer loop +:x + +# Appead a newline followed by the next input line to the pattern buffer +N + +# Remove all newlines from the pattern buffer +s/\n/ /g + + +# Inner loop +:y + +# Add a newline after the first 40 characters +s/(.@{40,40@})/\1\n/ + +# If there is a newline in the pattern buffer +# (i.e. the previous substitution added a newline) +/\n/ @{ + # There are newlines in the pattern buffer - + # print the content until the first newline. + P + + # Remove the printed characters and the first newline + s/.*\n// + + # branch to label 'y' - repeat inner loop + by + @} + +# No newlines in the pattern buffer - Branch to label 'x' (outer loop) +# and read the next input line +bx @end group @end example @codequoteundirected off @codequotebacktick off -The following command will split lines by comma character: + + +@exdent The wrapped output: @codequoteundirected on @codequotebacktick on @example @group -$ sed -E ':x @{N ; s/\n/ /g ; s/,/,\n/ ; /\n/!bx ; s/^ *// ; P ; D@}' \ - two-cities-mix.txt -It was the best of times, -it was the worst of times, -it was the age of wisdom, -it was the age of foolishness, +$ sed -E -f wrap40.sed two-cities-mix.txt +It was the best of times, it was the wor +st of times, it was the age of wisdom, i +t was the age of foolishness, @end group @end example @codequoteundirected off @codequotebacktick off -Both examples use similar construct: - -@itemize @bullet - -@item -The @samp{:x} is a label. It will be used later by the @command{b} command -to jump to the beginning of the @command{sed} program without starting -a new cycle. - -@item -The @samp{N} command reads the next line from the input file, and appends -it to the existing content of the pattern space (with a newline preceding it). - -@item -The first @samp{s/\n/ /g} command replaces all newlines with spaces, discarding -the line structure of the input file. - -@item -The second @samp{s///} command adds newlines based on the desired pattern -(after 40 characters in the first example, after comma character in the second -example). - -@item -The @samp{/\n/!bx} command searches for a newline in the pattern space -(@samp{/n/}), and if it is @emph{not} found (@samp{!}), branches (=jumps) -to the previously defined label @samp{x}. This will cause @command{sed} -to read the next line without processing any further commands in this cycle. - -@item -If a newline is found in the pattern space, @command{P} is used to print -up to the newline (that is - the newly structured line) then @command{D} -deletes the pattern space up to the newline, and starts a new cycle. -@end itemize -- 2.7.4 --------------6F0A7B5A42BC0B6287E76B53-- From unknown Fri Sep 19 23:53:49 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: bamber ward Subject: bug#28140: closed (Re: bug#28140: Here is a possible bug in documentation for 4.4) Message-ID: References: <6f25193e-2aac-12b0-f7b6-f3cf9b804fcc@gmail.com> X-Gnu-PR-Message: they-closed 28140 X-Gnu-PR-Package: sed Reply-To: 28140@debbugs.gnu.org Date: Sun, 29 Oct 2017 03:29:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1509247742-31280-1" This is a multi-part message in MIME format... ------------=_1509247742-31280-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #28140: Here is a possible bug in documentation for 4.4 which was filed against the sed package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 28140@debbugs.gnu.org. --=20 28140: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D28140 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1509247742-31280-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 28140-done) by debbugs.gnu.org; 29 Oct 2017 03:28:31 +0000 Received: from localhost ([127.0.0.1]:39613 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e8eH1-00087j-5K for submit@debbugs.gnu.org; Sat, 28 Oct 2017 23:28:31 -0400 Received: from mail-io0-f179.google.com ([209.85.223.179]:45351) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e8eGz-00087V-VK for 28140-done@debbugs.gnu.org; Sat, 28 Oct 2017 23:28:30 -0400 Received: by mail-io0-f179.google.com with SMTP id i38so20300924iod.2 for <28140-done@debbugs.gnu.org>; Sat, 28 Oct 2017 20:28:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:references:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=1DgVBpoZ98vd8AUNGGebQkp/xgc87GzL6vlvdK1I5YM=; b=L9v2IFNJf18gO24yli/3fls2JOs1qjVReMU7X+1vPokX0LKYFPcq2JbJZJ1vLdiAuc adB6v/HfPHYFFDilWRMPS6ve95Z7xBf8LnjZEbn3ECIM4mTw9GSBq3KhxITg4t8J0SXw l4CiBf1fNfpGLoxvlauf+i4g3v05pNLsvnJvFZLgJZ6bg6OPBwnnpXFbRBQ05qcxumHM 2OOhBo+HzAVKCJigLV/B33aDVjTjhzLk6XKmzGGSHo2uRhGE9kRlmhKXjXmrJdO8eWVZ JdU17JiWd22HuaLAZjW0fUIHHvibFKWRiisgb/DfvkXOvSylN0qxOHwbjd9a3nC9YqwJ FFTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=1DgVBpoZ98vd8AUNGGebQkp/xgc87GzL6vlvdK1I5YM=; b=Q7rzFK3ngqdGwY5xVZWju5VdFJpad85Jsy38sBY3YMGGxwDcbcvVCC/xFqbBuDo333 azYX2GWdbv/X2RCcnC9em7/RDGv0WaYCnoxhJXTrqgyfc449qos3du6d6KXTvmaGCXMR Mrtp/MqhgMuFE0e9L3nVQ0LlzdG6XjRSHVQ155ktETT7wLde+QLOvrpfzxjm9a6gjNpA zHPw4MSNEtrUmACBtFia+7iaJDnAzAfjGpTJfL4UFu9nrRh6KsIIa7ci+YXAPJiGiAEM R1aM19qF1YILMQvfqRHgCnEaIc2FzM1AWYfSLQijh92AfC1pFNXuxLj1LmE50BqUURTl 5HsQ== X-Gm-Message-State: AMCzsaWt/RNRmddVnomUsq657DDIVv5akMeJF/JqCQz/RG3x1tMNcbcU ACu6vg/exGyGeQjiuEsAiqwS17wP X-Google-Smtp-Source: ABhQp+SfpVrxBH/L99aeaKjZWDl4QoCFHozfzIlLhtqhIGo0stwk3dEQMS22FClEZ5+wbLe8PuyiKA== X-Received: by 10.36.4.212 with SMTP id 203mr1085440itb.10.1509247704001; Sat, 28 Oct 2017 20:28:24 -0700 (PDT) Received: from [192.168.88.239] (moose.housegordon.com. [184.68.105.38]) by smtp.googlemail.com with ESMTPSA id q191sm1609310itb.1.2017.10.28.20.28.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Oct 2017 20:28:23 -0700 (PDT) Subject: Re: bug#28140: Here is a possible bug in documentation for 4.4 From: Assaf Gordon To: bamber ward , 28140-done@debbugs.gnu.org References: <3e62a42a-d901-bc99-b0ee-bdd5dfab61f3@gmail.com> Message-ID: <6f25193e-2aac-12b0-f7b6-f3cf9b804fcc@gmail.com> Date: Sat, 28 Oct 2017 21:28:22 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 28140-done 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: -2.3 (--) On 2017-10-12 12:31 AM, Assaf Gordon wrote: >> On 18/08/17 09:34 AM, bamber ward wrote: >>> manual 4.4 >>> section 7-8 >>> sed -E ':x {N ; s/\n/ /g ; s/(.{40,40})/\1\n/ ; /\n/!bx ; P ;D}' >>> does not work as described. > > I'm thinking of the attached patch, > which replaces the overly terse (and incorrect) example > with a longer version with better comments. Push here: https://git.savannah.gnu.org/cgit/sed.git/commit/?id=490b4997 regards, - assaf ------------=_1509247742-31280-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 18 Aug 2017 15:34:25 +0000 Received: from localhost ([127.0.0.1]:44529 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dijI1-0006rK-HW for submit@debbugs.gnu.org; Fri, 18 Aug 2017 11:34:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:56571) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dijI0-0006r3-8c for submit@debbugs.gnu.org; Fri, 18 Aug 2017 11:34:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dijHu-00006s-4w for submit@debbugs.gnu.org; Fri, 18 Aug 2017 11:34:19 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=BAYES_50, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:36593) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dijHu-00006l-2D for submit@debbugs.gnu.org; Fri, 18 Aug 2017 11:34:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dijHs-0003Ix-OI for bug-sed@gnu.org; Fri, 18 Aug 2017 11:34:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dijHs-00005a-1Q for bug-sed@gnu.org; Fri, 18 Aug 2017 11:34:16 -0400 Received: from mail-qt0-x22b.google.com ([2607:f8b0:400d:c0d::22b]:37894) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dijHr-0008WU-Tk for bug-sed@gnu.org; Fri, 18 Aug 2017 11:34:15 -0400 Received: by mail-qt0-x22b.google.com with SMTP id t37so55458678qtg.5 for ; Fri, 18 Aug 2017 08:34:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=5lsBYSLpFElcYkdFqA5uP9RU/zDeTSURZ1K8vro3Hlk=; b=UMEDvg6xvnU3/tyyKCTm+F2zEuJr3JvQ6VcMVTdrn6c3BYAW3LmWyBvjkgp/YKvyDJ fHgiAslBaWG21ylu+5diwDRcm5gK2UQyNlZFLCeSVNnGtc1dQE097guMoEgVd7FS7ByT 18St0j1I3EqjTUqYXLtq63Q++sU5FN2GJ7IStXPlj0P/imiy6d0CApj3SEeCu2BDtd7O pfe778YdHFCcn9Dpkt3bpXSTLLmKJFme4o24s2qs8NvuyTR5gIUxTTFm6DnhgCyH+tJb 43xTkv7oBrVmwQhIEqEID2O8UtRPeT6rJbl3RzGO690EYyEu/UTcaENPyzWbPGJt7h18 L7gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=5lsBYSLpFElcYkdFqA5uP9RU/zDeTSURZ1K8vro3Hlk=; b=gAKTwqEK5/STEfvHtjscg1BaDEC/XMbmxobG3gfTWIR4or6Ll3qtywwDT4zx1BJTYb eaT8RxY6GihiRppEODLX+UTr4Ia84F57oFWilcw2mPCy75xSoZWlLQEmrzxSASfDTcVx Dyfj0la6Q37htsn1h53Kdv1QA4znjisnoA+lvzwI20WPWu5vQqLvAJqu66LBueJHvJ90 iXi44Qzl7pgVThza/YblvoINCX8Uas0l/tKw+z3nL4VxFmmYZQfb1A3wYfFOYNjftbRU jRImFFLn/6gxsFXCI5oW9zShvYHjhWdNkxReU6GOtdg4D2If3PiMxWXOyvNmJb1YPFQV 0e5g== X-Gm-Message-State: AHYfb5iS3WnJzQKU4GJnFULf4DC5RMzjkrCCGPYNJm+3208kye6qoXvA c52AwV3kcVHvYEa1tmvsROueQCJelIsBQMs= X-Received: by 10.200.15.84 with SMTP id l20mr6837039qtk.38.1503070453686; Fri, 18 Aug 2017 08:34:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.209.252 with HTTP; Fri, 18 Aug 2017 08:34:13 -0700 (PDT) From: bamber ward Date: Fri, 18 Aug 2017 16:34:13 +0100 Message-ID: Subject: Here is a possible bug in documentation for 4.4 To: bug-sed@gnu.org Content-Type: multipart/alternative; boundary="001a114e729276e62e055708dcc7" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -3.8 (---) X-Debbugs-Envelope-To: submit 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: -3.8 (---) --001a114e729276e62e055708dcc7 Content-Type: text/plain; charset="UTF-8" manual 4.4 section 7-8 sed -E ':x {N ; s/\n/ /g ; s/(.{40,40})/\1\n/ ; /\n/!bx ; P ;D}' does not work as described. Change line length , say to 5 sed -E ':x {N ; s/\n/ /g ; s/(.{5,5})/\1\n/ ; /\n/!bx ; P ;D}' cat line_wrap_input : apple grape pear peach pomengranate ~/sed/code-> sed -E ':x {N ; s/\n/ /g ; s/(.{5,5})/\1\n/ ; /\n/!bx ; P ; D}' \ line_wrap_input apple grap e pear peach pomengranate ~/sed/code-> This seems to work: #!/bin/sed -rf # line_wrap.sed ( :x { N s/\n/ /g :y s_(.{40,40})_\1\n_ /.{40,40}/ P s/.*\n// ty /\n/!bx } Best Wishes David L Ward --001a114e729276e62e055708dcc7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
manual 4.4
section 7-8
=C2=A0sed -E ':= x {N ; s/\n/ /g ; s/(.{40,40})/\1\n/ ; /\n/!bx ; P ;D}'
does not wor= k as described. Change line length , say to 5
=C2=A0 sed -E ':x {N ;= s/\n/ /g ; s/(.{5,5})/\1\n/ ; /\n/!bx ; P ;D}'=C2=A0
cat line_wrap= _input :
apple grape
pear peach
pomengranate

~/sed/code->= ; sed -E ':x {N ; s/\n/ /g ; s/(.{5,5})/\1\n/ ; /\n/!bx ; P ; D}' \= =C2=A0 line_wrap_input
apple
=C2=A0grap
e pear peach pomengranate<= br>

~/sed/code->

This seems to work:

#!/bin/sed -r= f
# line_wrap.sed (

:x
{
=C2=A0=C2=A0 N
=C2=A0=C2=A0 s= /\n/ /g
=C2=A0=C2=A0 :y
=C2=A0=C2=A0 s_(.{40,40})_\1\n_
=C2=A0=C2= =A0=C2=A0 /.{40,40}/=C2=A0 P
=C2=A0=C2=A0 s/.*\n//
=C2=A0=C2=A0 ty=C2=A0=C2=A0 /\n/!bx
=C2=A0=C2=A0
}

Best Wishes
<= /div>David L Ward
--001a114e729276e62e055708dcc7-- ------------=_1509247742-31280-1--