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.
--
Eric Blake ebl...@redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org