Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GUN Sed Bug

18 views
Skip to first unread message

王森

unread,
Oct 26, 2012, 8:42:41 AM10/26/12
to bug-gn...@gnu.org
Hi
### tmp.txt ###
[root@localhost learn_sed]# cat tmp.txt
hello world
I'am in china
[root@localhost learn_sed]#
[root@localhost learn_sed]# sed --version
GNU sed version 4.2.1
[root@localhost learn_sed]# which sed
/bin/sed
[root@localhost learn_sed]# /bin/sed 's/$/ End/' tmp.txt
hello world End
I'am in china End
[root@localhost learn_sed]#
[root@localhost learn_sed]#
[root@localhost learn_sed]# /bin/sed "s/\'/ End/" tmp.txt
hello world End
I'am in china End
[root@localhost learn_sed]#
### My Question
I want to know the reason. \' be equal to Line End ?
If possible , tell me why ? thanks

Eric Blake

unread,
Oct 26, 2012, 5:06:31 PM10/26/12
to 王森, bug-gn...@gnu.org
On 10/26/2012 06:42 AM, 王森 wrote:

> [root@localhost learn_sed]# /bin/sed "s/\'/ End/" tmp.txt
> hello world End
> I'am in china End
> [root@localhost learn_sed]#
> ### My Question
> I want to know the reason. \' be equal to Line End ?

Thanks for the report. However, this is not a bug, but a GNU extension,
as documented here:
https://www.gnu.org/software/sed/manual/html_node/Escapes.html#Escapes

In your particular case, end of line and end of input happen to match.
But if your sed script had also used commands like 'N', then you could
see a difference where multi-line mode makes \' match fewer places than $.

--
Eric Blake ebl...@redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org

signature.asc

Eric Blake

unread,
Oct 26, 2012, 5:10:35 PM10/26/12
to Eric Blake, bug-gn...@gnu.org, 王森
On 10/26/2012 03:06 PM, Eric Blake wrote:
> On 10/26/2012 06:42 AM, 王森 wrote:
>
>> [root@localhost learn_sed]# /bin/sed "s/\'/ End/" tmp.txt
>> hello world End
>> I'am in china End
>> [root@localhost learn_sed]#
>> ### My Question
>> I want to know the reason. \' be equal to Line End ?
>
> Thanks for the report. However, this is not a bug, but a GNU extension,
> as documented here:
> https://www.gnu.org/software/sed/manual/html_node/Escapes.html#Escapes
>
> In your particular case, end of line and end of input happen to match.
> But if your sed script had also used commands like 'N', then you could
> see a difference where multi-line mode makes \' match fewer places than $.

By the way, POSIX says \' in sed is not portable, because
implementations differ on whether it matches a literal ' or is treated
like the GNU extension. If you were trying to match the literal ', then
lose the backslash in your sed script.
signature.asc
0 new messages