Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 18 Jan 2010 20:14:30 +0100 (CET)
From:      Oliver Fromme <olli@lurza.secnetix.de>
To:        freebsd-hackers@FreeBSD.ORG, david@catwhisker.org, yanefbsd@gmail.com
Subject:   Re: User error or awk bug?
Message-ID:  <201001181914.o0IJEUXV000789@lurza.secnetix.de>
In-Reply-To: <7d6fde3d1001151402m74d999e5off14be9a99b5d187@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001181914.o0IJEUXV000789>