Re: sed numbered fields don't start from parenthesis
Eric Blake <[email protected]>
| Newsgroups | gmane.comp.gnu.utils.bugs |
|---|---|
| Organization | Red Hat, Inc. |
| Message-ID | <[email protected]> |
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
signature.asc
(application/pgp-signature, 539 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg iQEcBAEBCAAGBQJULUrBAAoJEKeha0olJ0NqaJQH/RXAW4WtpvZ+FsBZqVw43/3X sNorKLpLvq8zQ2N4hlvbXPc8YxzF1Df71HvgQTDGV1G7X8wUaqnTrs9WmX6vgnJY SqI0IfKiTi+8Yc5HWj4bUA4TZcta+RZOKqWFMBGn19W70ITO8vptBOucJxXw9BSe tSh6AchFJieHu9MKORFf3BGtpnCVt9OQXuuFsq3rsV3Vld7mKOI6ntsJ6pJ8ZVtm IODXbicSCZkTU3oSHmRgBwx7Ga9+o72npyvu2Awr2twg60XKVd94EFoqHt17GVQi qqDTU1+AdbXaqAUQH1z94hIs700gJBOQIG//rxDU4rh4LYCLOE+dzMccTubqIEI= =Qx6C -----END PGP SIGNATURE-----