From owner-freebsd-questions@freebsd.org Sun Jun 26 15:59:16 2016 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 978FAB81C31 for ; Sun, 26 Jun 2016 15:59:16 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5F9782F4A for ; Sun, 26 Jun 2016 15:59:16 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from r56.edvax.de (port-92-195-55-81.dynamic.qsc.de [92.195.55.81]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx02.qsc.de (Postfix) with ESMTPS id EFA212769B; Sun, 26 Jun 2016 17:49:39 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id u5QFndcw002378; Sun, 26 Jun 2016 17:49:39 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Sun, 26 Jun 2016 17:49:39 +0200 From: Polytropon To: =?UTF-8?B?RGFuacOrbA==?= de Kok Cc: freebsd-questions@freebsd.org Subject: Re: grep and anchoring Message-Id: <20160626174939.e3cd3a45.freebsd@edvax.de> In-Reply-To: <362EE01F-4B49-4ADB-A3A6-43F852FFF87F@danieldk.eu> References: <20232C89-B821-41EC-9188-C2A19C679BD8@danieldk.eu> <20160626163411.d05f863e.freebsd@edvax.de> <362EE01F-4B49-4ADB-A3A6-43F852FFF87F@danieldk.eu> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Jun 2016 15:59:16 -0000 On Sun, 26 Jun 2016 16:44:44 +0200, Daniël de Kok wrote: > On 26 Jun 2016, at 16:34, Polytropon wrote: > > Or is this just an "enrichment" your MUA added? :-) > > Yes, Mac’s Mail.app likes to replace these. I didn’t use an ellipsis > in the actual expression ;), just four dots. And it also seems to turn the apostrophe ' into a single closing quote ’. :-) > > % echo "1234 1234 1234" | egrep -o '^....' > > 1234 > > 123 > > 4 12 > [...] > > First 4-character pattern is "1234", next is " 123", > > and last is "4 12" (each 4 characters wide, as the > > space character " " is also "any character" that matches > > the . pattern). In the second example, the groups match > > 4 characters each ("1234" x 3). > > Note the anchoring (^), the pattern should only match any four > characters at the beginning of the line, so the expected output > is ‘1234’ and nothing more. ‘ 123' and '4 12' are not at the > beginning of the line and should consequently not be printed > to stdout. You're right; according to "man grep": -o, --only-matching Show only the part of a matching line that matches PATTERN. the first pattern matching "^...." should be the first 4 digits, the output should then stop, which really looks like a bug. Instead the pattern matching is repeated over the rest of the input line (leading to two "additional results"). > For comparison, the output of a recent GNU grep: > > — > % echo "1234 1234 1234" | grep -o '^....' > 1234 > — That is what _should_ happen, correct. Thanks for clarifying. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...