From unknown Sun Jun 22 22:42:36 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#27354 <27354@debbugs.gnu.org> To: bug#27354 <27354@debbugs.gnu.org> Subject: Status: strange behavior of sed Reply-To: bug#27354 <27354@debbugs.gnu.org> Date: Mon, 23 Jun 2025 05:42:36 +0000 retitle 27354 strange behavior of sed reassign 27354 sed submitter 27354 Han Lu severity 27354 normal tag 27354 notabug thanks From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 14 00:09:49 2017 Received: (at submit) by debbugs.gnu.org; 14 Jun 2017 04:09:49 +0000 Received: from localhost ([127.0.0.1]:46527 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dKzcq-0007Xd-Lh for submit@debbugs.gnu.org; Wed, 14 Jun 2017 00:09:49 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40890) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dKzIf-0006zz-4F for submit@debbugs.gnu.org; Tue, 13 Jun 2017 23:48:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dKzIY-0006SX-DH for submit@debbugs.gnu.org; Tue, 13 Jun 2017 23:48:51 -0400 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, HTML_MESSAGE,LOTS_OF_MONEY,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:37191) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dKzIY-0006ST-9r for submit@debbugs.gnu.org; Tue, 13 Jun 2017 23:48:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKzIU-0001gs-AN for bug-sed@gnu.org; Tue, 13 Jun 2017 23:48:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dKzIT-0006RV-1V for bug-sed@gnu.org; Tue, 13 Jun 2017 23:48:46 -0400 Received: from mail-oi0-x22e.google.com ([2607:f8b0:4003:c06::22e]:36422) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dKzIS-0006Qz-Rv for bug-sed@gnu.org; Tue, 13 Jun 2017 23:48:44 -0400 Received: by mail-oi0-x22e.google.com with SMTP id k145so72034441oih.3 for ; Tue, 13 Jun 2017 20:48:43 -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=js3p7s+njlCheXQbWSHs/x+KkuA/fIOBwmufPtTb+Jc=; b=uwFm51jBVEJf6FYPwvZ1ZE5b3tqXW+AVW/9a2tiFT5W6n6RUXSRZZ+ywOSead6wyf6 PEeAnMCYbkoi6DE2ZscqWUnd+ddskhF7/4FICJ10btrNEoG6BnWcUxFBGLTESdDRYQNL sDkqULnCxqtQS+18ymzbKJqrUqvczHd0l1DAYlrN9YBpnTRTc6sQeO8j135kn2TU7KOz IifEJQ8zk4I/kn2XsdGkdfwf5ExQB8Bk65OJdLPO3jHt0TRUOGOPwBXF0qwJMThqs0hM 3IRmsORiKPfWgxydLrXWizZ5N+ZiKUEK/Obm1RtYXg+BdefY/IvGgwcQIcVcIXLMwDN+ qp5w== 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=js3p7s+njlCheXQbWSHs/x+KkuA/fIOBwmufPtTb+Jc=; b=Mk4BhB5N3rHZuWMEd6JjwK0u2avMlDMJL2wAHOYOEKA62crXd47lEOeB+Dc5Zq5dsb tjqi4HTzUP5dQsKIuytqQbm1IwKl+nRXxlY/9Dn0L+mWrFFsW77oUhUrBHoh9DpIDqpI ArbuV4zJ7FcDoC4xZ6ql5voMKo4gRmntHSZXTKXWRAcjb7ZZGLQ4fbKjZGwfw/sl1acv p2TokvVVBkXio2zYeSkgnHpG6DFaFnCPx2HEWlQ0zpA1DTlrv/SUsrhtRgU1F7E7UxbB vzZXBjHmcLbBIvXevf2LURed84HHDQjBpiHJ6mN6s9RhbstB27Ta829MaMZApGD13slH CPDw== X-Gm-Message-State: AKS2vOwWn/r+oB8vu8ov0KV6MW3Bq4RsagR0mlLRy2tQyk13SG8sX7Le 1AcC5wtvbnv7y9XnvHG+yiPfkjDX1xyK X-Received: by 10.202.83.133 with SMTP id h127mr1795048oib.135.1497412122199; Tue, 13 Jun 2017 20:48:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.162.46 with HTTP; Tue, 13 Jun 2017 20:48:41 -0700 (PDT) From: Han Lu Date: Wed, 14 Jun 2017 11:48:41 +0800 Message-ID: Subject: strange behavior of sed To: bug-sed@gnu.org Content-Type: multipart/alternative; boundary="001a113dd546a04d160551e36dd2" 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: -4.0 (----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Wed, 14 Jun 2017 00:09:47 -0400 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: -4.0 (----) --001a113dd546a04d160551e36dd2 Content-Type: text/plain; charset="UTF-8" Hi Team, Please check this below: ~$ cat /etc/os-release NAME="Ubuntu" VERSION="14.04.5 LTS, Trusty Tahr" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 14.04.5 LTS" VERSION_ID="14.04" HOME_URL="http://www.ubuntu.com/" SUPPORT_URL="http://help.ubuntu.com/" BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" ~$ sed --version sed (GNU sed) 4.2.2 Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Jay Fenlason, Tom Lord, Ken Pizzini, and Paolo Bonzini. GNU sed home page: . General help using GNU software: . E-mail bug reports to: . Be sure to include the word ``sed'' somewhere in the ``Subject:'' field. Problem reproduce process: ~$ cat testfile 127.0.0.1 localhost hostname ::1 localhost ip6-localhost ip6-loopback The below command works as expected. ~$ sed -e 's/127.0.0.1/127/' -e "1i 127.0.0.1 localhost\n127.0.0.1 $HOSTNAME.domainname $HOSTNAME" testfile 127.0.0.1 localhost 127.0.0.1 node1.domainname node1 127 localhost hostname ::1 localhost ip6-localhost ip6-loopback But command below is not working as expeced: ~$ sed -e '/127.0.0.1/d' -e "1i 127.0.0.1 localhost\n127.0.0.1 $HOSTNAME.domainname $HOSTNAME" testfile ::1 localhost ip6-localhost ip6-loopback expected output: 127.0.0.1 localhost 127.0.0.1 node1.domainname node1 ::1 localhost ip6-localhost ip6-loopback If I add a comment at first line. then it's working. ~$ cat testfile # comment 127.0.0.1 localhost hostname ::1 localhost ip6-localhost ip6-loopback ~$ sed -e '/127.0.0.1/d' -e "1i 127.0.0.2 localhost\n127.0.0.2 $HOSTNAME.domainname $HOSTNAME" testfile 127.0.0.2 localhost 127.0.0.2 node1.domainname node1 # comment ::1 localhost ip6-localhost ip6-loopback --001a113dd546a04d160551e36dd2 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Team,

Please check this below:
=

~$ cat /etc/os-release
NAME=3D"Ubun= tu"
VERSION=3D"14.04.5 LTS, Trusty Tahr"
ID=3Dubuntu
ID_LIKE=3Ddebian
PRETTY_NAME=3D"Ubunt= u 14.04.5 LTS"
VERSION_ID=3D"14.04"
HOME= _URL=3D"http://www.ubuntu.com/&= quot;
BUG_REPORT_URL=3D"http://bugs.launchpad.net/ubuntu/&qu= ot;

~$ sed --version
sed (GNU= sed) 4.2.2
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Jay Fenlason, Tom Lord, Ken Pizzini,
and Paolo = Bonzini.
GNU sed home page: <http://www.gnu.org/software/sed/>.
General hel= p using GNU software: <http://ww= w.gnu.org/gethelp/>.
E-mail bug reports to: <bug-sed@gnu.org>.
Be sure to incl= ude the word ``sed'' somewhere in the ``Subject:'' field.


Problem reproduce process:

~$ cat testfile
127.0.0.1 localho= st hostname
::1 =C2=A0 =C2=A0 localhost ip6-localhost ip6-loopbac= k

The below command works as expected.=
~$ sed -e 's/127.0.0.= 1/127/' -e "1i 127.0.0.1 localhost\n127.0.0.1 $HOSTNAME.domain= name $HOSTNAME" testfile
127.0.0.1 localhost
127.0= .0.1 node1.domainname node1
127 localhost hostname
::1 = =C2=A0 =C2=A0 localhost ip6-localhost ip6-loopback

But command below is not working as expeced:
~$ sed -= e '/127.0.0.1/d' -e "1i 127= .0.0.1 localhost\n127.0.0.1 $HOSTNAME.domainname $HOSTNAME" testfile
::1 =C2=A0 =C2=A0 localhost ip6-localhost ip6-loopback
=

expected output:
127.0.0.1 localhost
127.0.0.1 node1.domainname node1
::1 =C2=A0 =C2=A0 localho= st ip6-localhost ip6-loopback

If I add a= comment at first line. then it's working.
~$ cat testfi= le
# comment
127.0.0.1 localhost hostname
::1= =C2=A0 =C2=A0 localhost ip6-localhost ip6-loopback

~$ sed -e '/127.0.0.1/d= ' -e "1i 127.0.0.2 localhost\n127.0.0.2 $HOSTNAME.domainname $HOST= NAME" testfile
127.0.0.2 localhost
127.0.0.2 node1= .domainname node1
# comment
::1 =C2=A0 =C2=A0 localhost= ip6-localhost ip6-loopback

--001a113dd546a04d160551e36dd2-- From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 14 02:19:57 2017 Received: (at submit) by debbugs.gnu.org; 14 Jun 2017 06:19:57 +0000 Received: from localhost ([127.0.0.1]:46579 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dL1em-0004QT-VS for submit@debbugs.gnu.org; Wed, 14 Jun 2017 02:19:57 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41164) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dKzK1-00072S-8Z for submit@debbugs.gnu.org; Tue, 13 Jun 2017 23:50:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dKzJu-0006uo-Uk for submit@debbugs.gnu.org; Tue, 13 Jun 2017 23:50:16 -0400 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, HTML_MESSAGE,LOTS_OF_MONEY,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:35206) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dKzJu-0006uh-R1 for submit@debbugs.gnu.org; Tue, 13 Jun 2017 23:50:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60363) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKzJt-0002PC-7R for bug-sed@gnu.org; Tue, 13 Jun 2017 23:50:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dKzJr-0006tT-S4 for bug-sed@gnu.org; Tue, 13 Jun 2017 23:50:13 -0400 Received: from mail-ot0-x231.google.com ([2607:f8b0:4003:c0f::231]:36049) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dKzJr-0006t9-Lh for bug-sed@gnu.org; Tue, 13 Jun 2017 23:50:11 -0400 Received: by mail-ot0-x231.google.com with SMTP id s7so8873147otb.3 for ; Tue, 13 Jun 2017 20:50:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=2ofnkszbDEEwN01z48aSonXUwqq3gbA0KYIML10J3Mk=; b=fRAK5/14dEzifZtZHTC4h41m04JnCQMgU40KGK1sU9VvCmSmrT+wM+Icrku6MIcE1Y 9GEzSi6sMVe2VLkrLXKCX6+wGHdJXLgIYPMEeOnsEfyMdxZtkCv6qg7H3vu2Kgo48vm5 bDuCPt0bkreoDdMvrMvNYMKNkrPTO4phIMjmzRw/9tjMg1hPlDfKkWYR0mHj1reHhYxe yX0PbojvsQxsB7XC+xfevIkB8Fk1lCdjfX1/JG2UYsuBoAEyo0Tq301/klEtBRY+RPqA /1rrGTF+w7rHxfG0t4R8r8D4ykWqF483If3mySZczeoo2F8YSZH7kwlpVhk+Nhed+9Vu 2LAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=2ofnkszbDEEwN01z48aSonXUwqq3gbA0KYIML10J3Mk=; b=OgvFmTE6YTcyZFfEJyU7tmyw5h/7Gkktf3jJr8s+oPzC6OSHSIg5OYRbKjXp/iHLhA NmJn/Bsq6OOO3Z4nxJevAF/Zrjybc1bYPgFbe42h41CKIrFVKK6lZet6z4Xxk4vmia5T 8bjgsM4J9/nKLEnAvxH8bVyACIblvOTOEbMMuEvBvfTNxkay/bRmC1XxMNcLXoxqOrAp 49Fx01UnROxNsxcEDUnAF8mELjU/MWjzm0/tzRQBZxR2W4WQlYOcwPaSiWrO/aqGR86j oeIGUXzBsfLY8D4fXUFeE036/B/CWGBnHucJ4eVks5RBwOH7jt4akbYQWdr7Q+y8+xYt CSLQ== X-Gm-Message-State: AKS2vOx1+ZE5zIycbha+BGYM7rBnBvUDEOGVYa75s13o1SlB1lWUMsth v1/h11cZz6rTvS5dJf8Rz9qP1RwFZOYf X-Received: by 10.157.1.23 with SMTP id 23mr2270066otu.251.1497412210746; Tue, 13 Jun 2017 20:50:10 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.162.46 with HTTP; Tue, 13 Jun 2017 20:50:10 -0700 (PDT) In-Reply-To: References: From: Han Lu Date: Wed, 14 Jun 2017 11:50:10 +0800 Message-ID: Subject: Re: strange behavior of sed To: bug-sed@gnu.org Content-Type: multipart/alternative; boundary="94eb2c03caa6e76bee0551e3721d" 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: -4.0 (----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Wed, 14 Jun 2017 02:19:56 -0400 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: -4.0 (----) --94eb2c03caa6e76bee0551e3721d Content-Type: text/plain; charset="UTF-8" sorry for the typo, the last command should be the below: ~$ sed -e '/127.0.0.1/d' -e "1i 127.0.0.1 localhost\n127.0.0.1 $HOSTNAME.domainname $HOSTNAME" testfile 127.0.0.1 localhost 127.0.0.1 node1.domainname node1 # comment ::1 localhost ip6-localhost ip6-loopback 2017-06-14 11:48 GMT+08:00 Han Lu : > Hi Team, > > Please check this below: > > ~$ cat /etc/os-release > NAME="Ubuntu" > VERSION="14.04.5 LTS, Trusty Tahr" > ID=ubuntu > ID_LIKE=debian > PRETTY_NAME="Ubuntu 14.04.5 LTS" > VERSION_ID="14.04" > HOME_URL="http://www.ubuntu.com/" > SUPPORT_URL="http://help.ubuntu.com/" > BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" > > ~$ sed --version > sed (GNU sed) 4.2.2 > Copyright (C) 2012 Free Software Foundation, Inc. > License GPLv3+: GNU GPL version 3 or later html>. > This is free software: you are free to change and redistribute it. > There is NO WARRANTY, to the extent permitted by law. > > Written by Jay Fenlason, Tom Lord, Ken Pizzini, > and Paolo Bonzini. > GNU sed home page: . > General help using GNU software: . > E-mail bug reports to: . > Be sure to include the word ``sed'' somewhere in the ``Subject:'' field. > > > Problem reproduce process: > > ~$ cat testfile > 127.0.0.1 localhost hostname > ::1 localhost ip6-localhost ip6-loopback > > The below command works as expected. > ~$ sed -e 's/127.0.0.1/127/' -e "1i 127.0.0.1 localhost\n127.0.0.1 > $HOSTNAME.domainname $HOSTNAME" testfile > 127.0.0.1 localhost > 127.0.0.1 node1.domainname node1 > 127 localhost hostname > ::1 localhost ip6-localhost ip6-loopback > > But command below is not working as expeced: > ~$ sed -e '/127.0.0.1/d' -e "1i 127.0.0.1 localhost\n127.0.0.1 > $HOSTNAME.domainname $HOSTNAME" testfile > ::1 localhost ip6-localhost ip6-loopback > > expected output: > 127.0.0.1 localhost > 127.0.0.1 node1.domainname node1 > ::1 localhost ip6-localhost ip6-loopback > > If I add a comment at first line. then it's working. > ~$ cat testfile > # comment > 127.0.0.1 localhost hostname > ::1 localhost ip6-localhost ip6-loopback > > ~$ sed -e '/127.0.0.1/d' -e "1i 127.0.0.2 localhost\n127.0.0.2 > $HOSTNAME.domainname $HOSTNAME" testfile > 127.0.0.2 localhost > 127.0.0.2 node1.domainname node1 > # comment > ::1 localhost ip6-localhost ip6-loopback > > --94eb2c03caa6e76bee0551e3721d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
sorry for the typo, the last command should be the below:<= div>
~$ sed -e '/127.= 0.0.1/d' -e "1i 127.0.0.1 localhost\n127.0.0.1 $HOSTNAME.domai= nname $HOSTNAME" testfile
127.0.0.1 localhost
127.= 0.0.1 node1.domainname node1
# comment
::1 =C2=A0 =C2= =A0 localhost ip6-localhost ip6-loopback

2017-06-14 11:48 GMT+08:00 Han Lu = <luhanwa@gmail.com>:
Hi Team,

Please check this below:
=
~$ cat /etc/os-release
NAME=3D"Ubuntu&qu= ot;
VERSION=3D"14.04.5 LTS, Trusty Tahr"
ID= =3Dubuntu
ID_LIKE=3Ddebian
PRETTY_NAME=3D"Ubuntu 1= 4.04.5 LTS"
VERSION_ID=3D"14.04"

~$ sed --version
sed (GNU sed) 4.2= .2
Copyright (C) 2012 Free Software Foundation, Inc.
Li= cense GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html&= gt;.
This is free software: you are free to change and redistribu= te it.
There is NO WARRANTY, to the extent permitted by law.

Written by Jay Fenlason, Tom Lord, Ken Pizzini,
<= div>and Paolo Bonzini.
GNU sed home page: <http://www.gnu.org/software/sed/>.
General help using GNU software: <http://www.gnu.org/gethelp/>.
Be sure to includ= e the word ``sed'' somewhere in the ``Subject:'' field.


Problem reproduce process:
=

~$ cat testfile
127.0.0.1 localhost= hostname
::1 =C2=A0 =C2=A0 localhost ip6-localhost ip6-loopback<= /div>

The below command works as expected.
~$ sed -e 's/127.0.0.1/127/' -e "1i 127.0.0.1 localhost\n127.0.0.1 = $HOSTNAME.domainname $HOSTNAME" testfile
127.0.0.1 localhost=
127.0.0.1 node1.domainname node1
127 localhost hostnam= e
::1 =C2=A0 =C2=A0 localhost ip6-localhost ip6-loopback

But command below is not working as expeced:
~$ sed -e '/12= 7.0.0.1/d' -e "1i 127.0.0.1 localhost\n127.0.0.1 $HOSTNAME.dom= ainname $HOSTNAME" testfile
::1 =C2=A0 =C2=A0 localhost ip6-= localhost ip6-loopback

expected output:
127.0.0.1 localhost
127.0.0.1 node1.domainname node1
::1 =C2=A0 =C2=A0 localhost ip6-localhost ip6-loopback

If I add a comment at first line. then it's wor= king.
~$ cat testfile
# comment
127.0.0.= 1 localhost hostname
::1 =C2=A0 =C2=A0 localhost ip6-localhost ip= 6-loopback

~$ sed -e '/127.0.0.1/d' -e "1i 127.0= .0.2 localhost\n127.0.0.2 $HOSTNAME.domainname $HOSTNAME" testfile
127.0.0.2 localhost
127.0.0.2 node1.domainname node1
=
# comment
::1 =C2=A0 =C2=A0 localhost ip6-localhost ip6-loop= back


--94eb2c03caa6e76bee0551e3721d-- From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 14 10:59:23 2017 Received: (at control) by debbugs.gnu.org; 14 Jun 2017 14:59:23 +0000 Received: from localhost ([127.0.0.1]:47854 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dL9lT-0004U1-Gw for submit@debbugs.gnu.org; Wed, 14 Jun 2017 10:59:23 -0400 Received: from mail-qk0-f170.google.com ([209.85.220.170]:34332) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dL9lQ-0004Ti-Rt; Wed, 14 Jun 2017 10:59:21 -0400 Received: by mail-qk0-f170.google.com with SMTP id d14so2895247qkb.1; Wed, 14 Jun 2017 07:59:20 -0700 (PDT) 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=IpeC8bnvREgn5iOXvUZXJdrOFoQWbPwBP1kYQNdJpf0=; b=Onmpcj07GBxrmZMWiwTH/SNDN8nqRCroqGZWsmgoCgOkxbdc82OXegbBMtV16lv6cX u7cvyv5VpAeVJ1Dx5t8Q/Q226sm2AhilsDEDPi79asN2r1nPUW4sMlLcszfo7tCF+7QG FKDtvIOIRvL9oW/Qcw8QuI9TiIDMQs0Gl+z3yIrqCRXE8S857tzeL7KK2IbSdYI+xB69 ls8P8z6DnmLjDRICAPB3kEjodjFJWgMsrdJkVUCpunrsTzSIij/45qIKZ8NTos51nvVz IcA1eqO2IZDx932VBE2klsD+5MPJW5hgRlM7o0iGPPjpQDCTtUEMsseRSAAoP0h2uRMq dE8Q== 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=IpeC8bnvREgn5iOXvUZXJdrOFoQWbPwBP1kYQNdJpf0=; b=kilyNYP3c8pSaQUZC5PeH4dDU1e0225aaSrC69kOm+zvuVDMxvFvJDPwFa9rPFF/VN Uy5Yyu4Czlvn8UOp56OGhop6HTdupRkSssiS/3FLgyrwjMeljFKh6RX0WNLm3r1pAObt rivsrWgqz9/mbqTDDmETNmmzrNWnfM7O/XGknyA5nGICsYhlNJC++o3eaKieGQN7xHlV gky+ne0M5yY0ranlP216QTfdSCEmFcFDRoO4o2XhG9t2iSfsJXwmJFaPA3eYfwh2q1QC gJCI+KKC8uGZacCW6Jzfn1G2hPv/Usi+qlY0qBBTKd2urF6iu5UlNHeEnaaJ96hmAcnI TYig== X-Gm-Message-State: AKS2vOydXpAFhb2wjHlpgmkfqAcHE+cssnbKOAfoEzrXXjexypUJMqxN dnSuxT8OI1yT6w== X-Received: by 10.55.73.132 with SMTP id w126mr605376qka.31.1497452355049; Wed, 14 Jun 2017 07:59:15 -0700 (PDT) Received: from gmail.com (housegordon.org. [104.236.108.240]) by smtp.gmail.com with ESMTPSA id p19sm132764qki.65.2017.06.14.07.59.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Jun 2017 07:59:14 -0700 (PDT) Date: Wed, 14 Jun 2017 14:58:35 +0000 From: Assaf Gordon To: Han Lu Subject: Re: bug#27354: strange behavior of sed Message-ID: <20170614145834.GA8303@gmail.com> References: 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.0 (/) X-Debbugs-Envelope-To: control Cc: 27354-done@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.0 (/) tag 27354 notabug thanks Hello, On Wed, Jun 14, 2017 at 11:48:41AM +0800, Han Lu wrote: [...] >The below command works as expected. >~$ sed -e 's/127.0.0.1/127/' -e "1i 127.0.0.1 localhost\n127.0.0.1 [...] >But command below is not working as expeced: >~$ sed -e '/127.0.0.1/d' -e "1i 127.0.0.1 localhost\n127.0.0.1 First, thank you for providing such clear information on how to reproduce your output - it makes troubleshooting much easier. This is not a bug in sed, but a side-effect of the 'd' (=delete) command: when sed executes the 'd' command, it immediately starts a new cycle (i.e. skips all other commands, reads the next line of the input, and starts from the first sed command). In your example, the sequence is: 1. sed reads the first input line (it contains '127.0.0.1') 2. the 'd' command is executed - line is deleted and not printed, and sed restarts a new cycle: it skips all other commands and reads the next input line. 4. The first time the '1i' command is executed, sed is already on the second input line, and the address '1' is never matched - the command is never executed. This also explains why it does work when you add a dummy comment line: The '/127.0.0.1/d' does not match the first line, and then the '1i' command is matched and executed. A simple work-around would be to put the 'i' command before the 'd' command, like so: sed -e '1i 127.0.0.1 ....' -e '/127/d' As such, I'm marking this as 'not a bug', but discussion can continue by replying to this thread. regards, - assaf From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 20 02:26:30 2017 Received: (at 27354-done) by debbugs.gnu.org; 20 Jun 2017 06:26:30 +0000 Received: from localhost ([127.0.0.1]:56889 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNCcQ-0005ZY-3y for submit@debbugs.gnu.org; Tue, 20 Jun 2017 02:26:30 -0400 Received: from mail-ot0-f175.google.com ([74.125.82.175]:32794) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNCav-0005Wq-Vd for 27354-done@debbugs.gnu.org; Tue, 20 Jun 2017 02:24:58 -0400 Received: by mail-ot0-f175.google.com with SMTP id y47so60636364oty.0 for <27354-done@debbugs.gnu.org>; Mon, 19 Jun 2017 23:24:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=I3YCuJsqqH0PdYLxvGwTBSxq159ZHpATdf8jSw8vvno=; b=cnbFdyxU3YLFKvArXdnnVVeH0B/elWwlXg8WYP9FIisSW5pFBQDxmLXtle1YVF6AGK YmVGMTAsmd27wMzZV1k9P40gZfJY7JNyNhVmg7Fg2JzKokf3C4Y2GWfD3k9NfeYBP10N kHSFsk5PFtxIYFgNt4h6RDVuD2kjHK+uLTxyKFo79Yx9gsEi9m+UBitNUFXd4W6cGooS ESuJ7pqhUd2BW8bWYRbtg2BgGuELFakLW0nvOtEDiR9zn/beopd4rpbo7gjc497Y4AN0 Tolx5LibZxM9CQLVCFwMkDfTlE9EymBgdCESeXVPZz122gfAUyoFSutSshclKcfHKLjc 7Q8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=I3YCuJsqqH0PdYLxvGwTBSxq159ZHpATdf8jSw8vvno=; b=OCLo2vyrea5EBguIQb0ev7wOKjWuZEczvp6qGBbfMX1UCb1g/rKVggoHBF8OgPEQ3V f33CBet2lpg79cT4O9NCqEJYXuvW+bwTokfmuW1oxIJHN708QjLIiKYDaAlTA/NBpvzO ztCmyxOXcUy6hcX2HtqLJXMd/E4AXj+Mm7VOPHZka5pNzouNwtZ8us3ksq0CeRf8a3Uc TRcxX5ZMqVzAYjSrJJGFEBdpDJPFiQzs2m/NXOR/i4/Fgzvcc9eZFFzbluOgsLpmuvu3 ejWlQiEhBV8CSCH0DXCs0nyVgarJ1vZgcvR7Il4H3x4Jv2PxN96rbite2SVY9BCpxIKg ChVg== X-Gm-Message-State: AKS2vOz4k9WDebZLUo1TG2NjTiBC7ty3L31BZBb4AEg8WGsm9Ra4mW8T Y0hpEN9t+oUJXm690SZApwjvMq9LJA== X-Received: by 10.157.43.199 with SMTP id u65mr16391128ota.182.1497939892158; Mon, 19 Jun 2017 23:24:52 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.162.46 with HTTP; Mon, 19 Jun 2017 23:24:51 -0700 (PDT) In-Reply-To: <20170614145834.GA8303@gmail.com> References: <20170614145834.GA8303@gmail.com> From: Han Lu Date: Tue, 20 Jun 2017 14:24:51 +0800 Message-ID: Subject: Re: bug#27354: strange behavior of sed To: Assaf Gordon Content-Type: multipart/alternative; boundary="001a113cffd22acb8f05525e4fed" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 27354-done X-Mailman-Approved-At: Tue, 20 Jun 2017 02:26:29 -0400 Cc: 27354-done@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.0 (/) --001a113cffd22acb8f05525e4fed Content-Type: text/plain; charset="UTF-8" Hi Assaf, Thanks for the explanation. But if I put 'i' command before 'd' command, shouldn't the input new lines be deleted ? Since new inputed lines contain the pattern 'd' command want. Br, Xingming 2017-06-14 22:58 GMT+08:00 Assaf Gordon : > tag 27354 notabug > thanks > > Hello, > On Wed, Jun 14, 2017 at 11:48:41AM +0800, Han Lu wrote: > [...] > >> The below command works as expected. >> ~$ sed -e 's/127.0.0.1/127/' -e "1i 127.0.0.1 localhost\n127.0.0.1 >> > [...] > >> But command below is not working as expeced: >> ~$ sed -e '/127.0.0.1/d' -e "1i 127.0.0.1 localhost\n127.0.0.1 >> > > First, > thank you for providing such clear information on how to > reproduce your output - it makes troubleshooting much easier. > > This is not a bug in sed, but a side-effect of the 'd' (=delete) > command: when sed executes the 'd' command, it immediately starts > a new cycle (i.e. skips all other commands, reads the next line of the > input, and starts from the first sed command). > > In your example, the sequence is: > 1. sed reads the first input line (it contains '127.0.0.1') > 2. the 'd' command is executed - line is deleted and not printed, > and sed restarts a new cycle: > it skips all other commands and reads the next input line. > 4. The first time the '1i' command is executed, sed is already > on the second input line, and the address '1' is never matched - > the command is never executed. > > This also explains why it does work when you add a dummy comment line: > The '/127.0.0.1/d' does not match the first line, > and then the '1i' command is matched and executed. > > A simple work-around would be to put the 'i' command > before the 'd' command, like so: > > sed -e '1i 127.0.0.1 ....' -e '/127/d' > > As such, I'm marking this as 'not a bug', > but discussion can continue by replying to this thread. > > regards, > - assaf > > > > --001a113cffd22acb8f05525e4fed Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Assaf,

Thanks for the explanation.

But if I put 'i' command before 'd'= command, shouldn't the input new lines be deleted ? Since new inputed = lines contain the pattern 'd' command want.

Br,
Xingming

2017-06-14 22:58 GMT+08:00 Assaf Gordon <assafgordo= n@gmail.com>:
tag 27354 not= abug
thanks

Hello,
On Wed, Jun 14, 2017 at 11:48:41AM +0800, Han Lu wrote:
[...]
The below command works as expected.
~$ sed -e 's/127.0.0.1/127/' -e "1i 127.0.0.1 localhost\n127.0= .0.1
[...]
But command below is not working as expeced:
~$ sed -e '/127.0.0.1/d' -e "1i 127.0.0.1 localhost\n127.0.0.1

First,
thank you for providing such clear information on how to
reproduce your output - it makes troubleshooting much easier.

This is not a bug in sed, but a side-effect of the 'd' (=3Ddelete)<= br> command: when sed executes the 'd' command, it immediately starts a new cycle (i.e. skips all other commands, reads the next line of the inpu= t, and starts from the first sed command).

In your example, the sequence is:
1. sed reads the first input line (it contains '127.0.0.1')
2. the 'd' command is executed - line is deleted and not printed, =C2=A0 and sed restarts a new cycle:
=C2=A0 it skips all other commands and reads the next input line.
4. The first time the '1i' command is executed, sed is already
=C2=A0 on the second input line, and the address '1' is never match= ed -
=C2=A0 the command is never executed.

This also explains why it does work when you add a dummy comment line:
The '/127.0.0.1/d' does not match the first line,
and then the '1i' command is matched and executed.

A simple work-around would be to put the 'i' command
before the 'd' command, like so:

=C2=A0 =C2=A0sed -e '1i 127.0.0.1 ....' -e '/127/d'

As such, I'm marking this as 'not a bug',
but discussion can continue by replying to this thread.

regards,
- assaf




--001a113cffd22acb8f05525e4fed-- From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 21 16:19:46 2017 Received: (at 27354-done) by debbugs.gnu.org; 21 Jun 2017 20:19:46 +0000 Received: from localhost ([127.0.0.1]:60304 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNm6L-0003Ww-TR for submit@debbugs.gnu.org; Wed, 21 Jun 2017 16:19:46 -0400 Received: from mail-qk0-f182.google.com ([209.85.220.182]:34859) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNm6K-0003Wi-5e for 27354-done@debbugs.gnu.org; Wed, 21 Jun 2017 16:19:44 -0400 Received: by mail-qk0-f182.google.com with SMTP id 16so6000786qkg.2 for <27354-done@debbugs.gnu.org>; Wed, 21 Jun 2017 13:19:44 -0700 (PDT) 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=ceM7UP+bBHer17jHJdE7toP3KRhKIVvxmo8kaRIy4Hc=; b=V0zHJzD62qpIib5cPQMZ2xLavlJ19LDvjRXEcHhuzvtN0UlWu8nH9cjTKw/m/MOaZy hEBH332XlNTZK/L3r6pouanyG34S7q3mS2mB1hxlxqGeIuslAF4Z1iIxynBXpSaB1SZT xY9j9F2EiRq8BxtiZBeSyjZAQvkHDybZ4s0MJ5DaUXmnCOU4HPJ2fQ/BEstQn5STpfBY YHJIbe4fTu0umjFkozDr3oP8kvAzqoSVdyGoFutMGKmmbs6tFu4AShXZyXHNznXyeJ5y I5Qdzr4g2SpfCYqOalsb243kP0I/HjB6BVJg3QwQjVrrztJCsATyG9LspwqPMsJM3jm/ hq7Q== 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=ceM7UP+bBHer17jHJdE7toP3KRhKIVvxmo8kaRIy4Hc=; b=I1IQcY/J9wO1uM4Xq5/toH0ZNLWiyLMtcdfZTqoDO99uWK4syVMwvXn5LB2maDmEQr V/YN0klW6k68+vQZ/DyWjYrSwcg/xBRS8XY/iURHihuhCv6+c/AkuSI+E4dxXX7wbtBx 8aE0gsqe7DDWfqzEP0dP6xbS4ZNZ1vEfYk0HVhOhhyzdW8MM5wI2zSJebKZGkumt6dXP Y3SGIaorcmDr/hMQWFk/62Y8ZbDNU0Uh8/YVgeT22IQp0BzvAWlEDeFX3CHdkuFtZFg2 0aed84WMYU+ptJYwOOvwyWl0j1MW2IXAsK1CuyAznh5wEcFDmBV1OGabWyabd27SK1WA iQ4Q== X-Gm-Message-State: AKS2vOxmaeKH09p9XO/IKfiqEBXOEMDeeVIfVgDibngfE4HNJooK4pYf Pv+5Q2M9g360kg== X-Received: by 10.55.14.85 with SMTP id 82mr45745212qko.193.1498076378510; Wed, 21 Jun 2017 13:19:38 -0700 (PDT) Received: from gmail.com (housegordon.org. [104.236.108.240]) by smtp.gmail.com with ESMTPSA id r191sm10933216qke.22.2017.06.21.13.19.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Jun 2017 13:19:37 -0700 (PDT) Date: Wed, 21 Jun 2017 20:18:59 +0000 From: Assaf Gordon To: Han Lu Subject: Re: bug#27354: strange behavior of sed Message-ID: <20170621201857.GA19454@gmail.com> References: <20170614145834.GA8303@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.0 (/) X-Debbugs-Envelope-To: 27354-done Cc: 27354-done@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.0 (/) Hello, On Tue, Jun 20, 2017 at 02:24:51PM +0800, Han Lu wrote: >But if I put 'i' command before 'd' command, shouldn't the input new lines >be deleted ? Since new inputed lines contain the pattern 'd' command want. There is a subtlely in the 'i' (insert) command: The added content is not stored in the pattern space and is not subject to later manipulations (such as pattern matching, 's///' and 'd'). The GNU sed manual says: i = Immediately output the lines of text which follow this command. Observe the following: $ seq 3 | sed -e 1iX -e 's/X/Y/' X 1 2 3 And similarly with match+delete command: $ seq 3 | sed -e 1iX -e '/X/d' X 1 2 3 Similar subtlety also applies to 'a' (append) and 'c' (change) commands. The manual should probably be improved to explicitly mention these points (added to my mental 'todo' list). regards, - assaf From unknown Sun Jun 22 22:42:36 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 20 Jul 2017 11:24:05 +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