From owner-freebsd-questions@freebsd.org Mon Oct 5 22:57:56 2015 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 EEA169B9422 for ; Mon, 5 Oct 2015 22:57:56 +0000 (UTC) (envelope-from quartz@sneakertech.com) Received: from douhisi.pair.com (douhisi.pair.com [209.68.5.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id CA511CB3 for ; Mon, 5 Oct 2015 22:57:56 +0000 (UTC) (envelope-from quartz@sneakertech.com) Received: from [10.2.2.1] (pool-108-49-223-195.bstnma.fios.verizon.net [108.49.223.195]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by douhisi.pair.com (Postfix) with ESMTPSA id C55CD3F741 for ; Mon, 5 Oct 2015 18:57:54 -0400 (EDT) Message-ID: <56130072.9070406@sneakertech.com> Date: Mon, 05 Oct 2015 18:57:54 -0400 From: Quartz MIME-Version: 1.0 To: freebsd-questions@freebsd.org Subject: Re: awk question References: <5611C922.4050007@hiwaay.net> <20151005042129.1f153ec6.freebsd@edvax.de> <5611F776.9090701@hiwaay.net> <56124479.9020505@sneakertech.com> <20151005165902.ad01c288.freebsd@edvax.de> <5612EF57.10207@sneakertech.com> <20151005235812.eee38247.freebsd@edvax.de> In-Reply-To: <20151005235812.eee38247.freebsd@edvax.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Oct 2015 22:57:57 -0000 >> It's not very much like sh or C syntax (or >> any other syntax) and new users tend to get really confused. > > Hmmm... I don't know, could you provide an example where you > would say, like, "this is not intuitive" or even "this does > something totally strange"? Things I've noticed new users bump into all the time: Statements must be wrapped in curly braces, ie; > awk '{print $1}{print $2}' I think awk is one of the few languages to do this. Because of the above, having to type: > awk '{print $1}' instead of just" > awk 'print $1' .. in other words both the quotes and the curly braces are required. For most other shell utilities one is enough. People assume that awk prints string literals like (ba)sh: > echo "$1$2$3" and > awk '{print $1$2$3}' both yield fields with nothing between them. So far so good, right? but: > echo "$1,$2,$3" yields results with commas between them, but: > awk '{print $1,$2,$3}' yields results with spaces. OK, so it's not like sh. Maybe it's like Javascript then? > awk '{print $1+","+$2+","+$3}' ... nope, now all they get is a huge list of mostly zeros, because awk doesn't overload operators. (Note: I am not advocating for overloaded operators and I think Javascript is a horrible language). > Yes, this is true, but keep in mind what awk is: a "pattern-directed > scanning and processing language". If you want higher precision > math, use system(" | dc") and incorporate the result; > awk isn't really for math, but integer math is usually fine. :-) Right, but it's just something that makes people shy away from awk, for better or worse.