From owner-freebsd-questions@FreeBSD.ORG Thu Aug 2 12:14:03 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 76BF4106564A for ; Thu, 2 Aug 2012 12:14:03 +0000 (UTC) (envelope-from kaltheat@zoho.com) Received: from sender1.zohomail.com (sender1.zohomail.com [72.5.230.103]) by mx1.freebsd.org (Postfix) with ESMTP id 5DBB98FC0C for ; Thu, 2 Aug 2012 12:14:03 +0000 (UTC) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=zapps768; d=zoho.com; h=date:from:to:message-id:subject:mime-version:content-type:user-agent:sender; b=Nj624lhFGXyO9vibw2sBv29xYVAGgeg95A8bvee67JfEwXlr12zVKAs5n4s3zNBVYGPBUxWJ1KSP hv+RtZx0/6+q+Ok/uBS7YMq0HEGkskuCOGOps6g74JoK0pXvTacJ Received: from 172.29.249.242 (172.29.249.242 [172.29.249.242]) by mx.zohomail.com with SMTP id 1343906452330361.9267909600592; Thu, 2 Aug 2012 04:20:52 -0700 (PDT) Date: Thu, 02 Aug 2012 13:20:52 +0200 From: kaltheat To: Message-ID: <743721353.9443.1343906452119.JavaMail.sas1@172.29.249.242> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Priority: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail Sender: kaltheat@zoho.com Subject: buggy awk regex handling? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Aug 2012 12:14:03 -0000 Hi, I tried to replace three letters with three letters by awk using the sub-routine. I assumed that my regular expression does mean the following: match if three letters of any letter of alphabet occurs anywhere in input $ echo AbC | awk '{sub(/[[:alpha:]]{3}/,"cBa"); print;}' AbC As you can see the result was unexpected. When I try doing it for at least one letter, it works: $ echo AbC | awk '{sub(/[[:alpha:]]+/,"cBa"); print;}' cBa Same problem without macro: $ echo AbC | awk '{sub(/[A-Za-z]{3}/,"cBa"); print;}' AbC $ echo AbC | awk '{sub(/[A-Za-z]+/,"cBa"); print;}' cBa I thought that it might have something to do with the curly braces. But escaping them doesn't do the trick. What am I doing wrong? Or is awk buggy? Regards, kaltheat