bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sed numbered fields don't start from parenthesis


From: Eric Blake
Subject: Re: sed numbered fields don't start from parenthesis
Date: Thu, 02 Oct 2014 06:53:21 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.1

On 10/02/2014 06:41 AM, blind Pete wrote:
> Hi, 
> 
> I believe that the output from the following should be "Sep", not
> "28th_Sep".  The result can be changed by adding a ".*" to the 
> start of the search string, but I don't think that that should be 
> necessary.  Removing the trailing ".*" also produces odd results.  

Sorry, but the behavior you see is mandated by POSIX, and not a bug.

> 
> Using Ubuntu 12.04 LTS. 
> 
> $ echo 28th_September_2014 | sed "s/\(sep\).*/\1/i"

The s/// command has two steps: first, find the matching portion of the
entire line:

28th_September_2014
     ^^^^^^^^^^^^^^

then replace the portion of the line that matched with the substitution
string:

28th_Sep

You _do_ have to use .* on both front and end of the pattern if you want
to shorten an entire line down to just a matched backref number.

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

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]