From root@gits.dyndns.org Sun Aug 6 20:45:56 2000 Return-Path: Received: from racine.cybercable.fr (racine.cybercable.fr [212.198.0.201]) by hub.freebsd.org (Postfix) with SMTP id B7B6E37BC66 for ; Sun, 6 Aug 2000 20:45:54 -0700 (PDT) (envelope-from root@gits.dyndns.org) Received: (qmail 9200421 invoked from network); 7 Aug 2000 03:45:53 -0000 Received: from r227m167.cybercable.tm.fr (HELO gits.dyndns.org) ([195.132.227.167]) (envelope-sender ) by racine.cybercable.fr (qmail-ldap-1.03) with SMTP for ; 7 Aug 2000 03:45:53 -0000 Received: (from root@localhost) by gits.dyndns.org (8.9.3/8.9.3) id FAA24264; Mon, 7 Aug 2000 05:45:52 +0200 (CEST) (envelope-from root) Message-Id: <200008070345.FAA24264@gits.dyndns.org> Date: Mon, 7 Aug 2000 05:45:52 +0200 (CEST) From: Cyrille Lefevre Sender: root@gits.dyndns.org Reply-To: Cyrille Lefevre To: FreeBSD-gnats-submit@freebsd.org Subject: strange behaviour of sed 's/ */ /' w/ or w/o g X-Send-Pr-Version: 3.2 >Number: 20449 >Category: bin >Synopsis: strange behaviour of sed 's/ */ /' w/ or w/o g >Confidential: no >Severity: critical >Priority: high >Responsible: freebsd-bugs >State: closed >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Aug 06 20:50:00 PDT 2000 >Closed-Date: Mon Aug 7 01:58:24 PDT 2000 >Last-Modified: Mon Aug 07 01:59:09 PDT 2000 >Originator: Cyrille Lefevre >Release: FreeBSD 4.1-RC i386 >Organization: ACME >Environment: FreeBSD gits 4.1-RC FreeBSD 4.1-RC #0: Tue Jul 18 01:55:07 CEST 2000 root@gits:/disk2/4.0-stable/obj/disk2/4.0-stable/src/sys/CUSTOM i386 >Description: well, sed(1) substitutions seems to be very buggy. see below. maybe it's regex(3), don't know yet. >How-To-Repeat: $ echo 'a string with spaces' | sed 's/ */ /' a string with spaces a space is prepended instead of replacing the first 2 spaces w/ one. $ echo 'a string with spaces' | sed 's/ */ /g' a s t r i n g w i t h s p a c e s all empty strings are matched instead of matching spaces $ echo 'a string with spaces' | sed 's/g*/x/g' xax x xsxtxrxixnx xwxixtxhx x xsxpxaxcxexsx $ echo 'a string with spaces' | sed 's/z*/x/g' xax x xsxtxrxixnxgx xwxixtxhx x xsxpxaxcxexsx in fact, not only space substitutions are very buggy. >Fix: n/a >Release-Note: >Audit-Trail: From: Gregory Bond To: Cyrille Lefevre Cc: FreeBSD-gnats-submit@FreeBSD.ORG Subject: Re: bin/20449: strange behaviour of sed 's/ */ /' w/ or w/o g Date: Mon, 07 Aug 2000 14:14:26 +1000 > $ echo 'a string with spaces' | sed 's/ */ /' > a string with spaces This is exactly what you've asked for: the first place which matches / */ (i.e. 0 or more spaces, i.e. the empty string at the beginning of the line) is replaced with a space. Similarly with the other 3 examples. Check up the meaning of "*" in regex(3). State-Changed-From-To: open->closed State-Changed-By: sheldonh State-Changed-When: Mon Aug 7 01:58:24 PDT 2000 State-Changed-Why: You've shown us some examples of sed(1) doing the right thign. If you need help with regular expressions, there are some pretty keen beans on the freebsd-questions mailing list. :-) http://www.freebsd.org/cgi/query-pr.cgi?pr=20449 >Unformatted: