From owner-freebsd-hackers@FreeBSD.ORG Mon Jan 18 19:15:32 2010 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9C0FA1065694 for ; Mon, 18 Jan 2010 19:15:32 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [IPv6:2a01:170:102f::2]) by mx1.freebsd.org (Postfix) with ESMTP id 23BD88FC19 for ; Mon, 18 Jan 2010 19:15:31 +0000 (UTC) Received: from lurza.secnetix.de (localhost [127.0.0.1]) by lurza.secnetix.de (8.14.3/8.14.3) with ESMTP id o0IJEUPK000790; Mon, 18 Jan 2010 20:14:46 +0100 (CET) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.14.3/8.14.3/Submit) id o0IJEUXV000789; Mon, 18 Jan 2010 20:14:30 +0100 (CET) (envelope-from olli) Date: Mon, 18 Jan 2010 20:14:30 +0100 (CET) Message-Id: <201001181914.o0IJEUXV000789@lurza.secnetix.de> From: Oliver Fromme To: freebsd-hackers@FreeBSD.ORG, david@catwhisker.org, yanefbsd@gmail.com In-Reply-To: <7d6fde3d1001151402m74d999e5off14be9a99b5d187@mail.gmail.com> X-Newsgroups: list.freebsd-hackers User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (FreeBSD/6.4-PRERELEASE-20080904 (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.2 (lurza.secnetix.de [127.0.0.1]); Mon, 18 Jan 2010 20:14:46 +0100 (CET) Cc: Subject: Re: User error or awk bug? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Jan 2010 19:15:32 -0000 Garrett Cooper wrote: > David Wolfskill wrote: > > How about: > > > > d254(6.4-S)[10] echo //////// | awk '{ gsub (/\/\/+/, "/"); print }' > > / > > d254(6.4-S)[11] > > > > then? > > This works very well. Is the expression quantifier operator [ `{' > ] not supported in awk like perl, python, tcl, etc? awk is quite old. It implements the historical behaviour of egrep which did not support braces (this is mentioned in the manual page). Braces are a relatively new feature in egrep. They were probably never added to awk because of compatibility issues with existing scripts. By the way, you can use strings as regular expressions so you don't have to enclose them in slashes. This saves you from the ugly escaping with backslashes: echo //////// | awk '{gsub ("/+", "/"); print}' will do what you want. On the other hand, the typical tool for simple search+replace tasks is sed: echo //////// | sed 's=//*=/=g' By the way, when egrep parses brace expressions, it simply translates them to standard expressions. So, when it sees "/{2,}" it converts it to "//+" before creating the DFA. Best regards Oliver -- Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M. Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün- chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd "The scanf() function is a large and complex beast that often does something almost but not quite entirely unlike what you desired." -- Chris Torek