From owner-freebsd-questions@FreeBSD.ORG Sun Nov 2 05:10:04 2008 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 52002106564A for ; Sun, 2 Nov 2008 05:10:04 +0000 (UTC) (envelope-from the.real.david.allen@gmail.com) Received: from wf-out-1314.google.com (wf-out-1314.google.com [209.85.200.175]) by mx1.freebsd.org (Postfix) with ESMTP id 253F38FC26 for ; Sun, 2 Nov 2008 05:10:04 +0000 (UTC) (envelope-from the.real.david.allen@gmail.com) Received: by wf-out-1314.google.com with SMTP id 24so1942359wfg.7 for ; Sat, 01 Nov 2008 22:10:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=A9xFJwb6QH/Gard64ToHn7SqH4ca/6jEGrrhZeRmeH0=; b=Qv+kpWIjKCu895E2l0Zy56m/uQoxd2CaRV3giRthSWVgYFfsDOP5mdrHUXW8ZVAlfF c/Rh/T2u5tTh5ZQGBjY+dtKsFCyX3OOk5wExKuR3a9nN6ut0TR7moSn5T5+OXnUf6+Id iupqqQ+i2PYO2WZNAI3e2KlsX8xsj0ml/dQEc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=U4+XRfOWA+bGi6roRofg3gT6e7SjHNiwYlTm/uXUY/1pm5K/5JAk7s7mPZ8X6YyzaD 3B7Bl91wzgt7FeGWR+Nxqkm+WCPJmIbM2CDI9LPG9miR+ENJO4OrHFKsGQ9+kroCaKtH CkLWX2ekJvCtJre5w7u32tP8EgefC/n0LxKxA= Received: by 10.142.90.16 with SMTP id n16mr6436372wfb.130.1225602603851; Sat, 01 Nov 2008 22:10:03 -0700 (PDT) Received: by 10.143.18.2 with HTTP; Sat, 1 Nov 2008 22:10:03 -0700 (PDT) Message-ID: <2daa8b4e0811012210k40e92816ydbc96e36abe9ee5@mail.gmail.com> Date: Sat, 1 Nov 2008 21:10:03 -0800 From: "David Allen" To: "freebsd-questions@freebsd.org" In-Reply-To: <20081102045414.GA13745@shepherd> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <2daa8b4e0811011821q210ae3a5j8f612a0fc79e8844@mail.gmail.com> <20081102045414.GA13745@shepherd> Cc: Sahil Tandon Subject: Re: OT: Shell Script using Awk 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: Sun, 02 Nov 2008 05:10:04 -0000 On 11/1/08, Sahil Tandon wrote: > David Allen wrote: > >> My apologies for asking on this list, but I'm stuck without Perl and need >> to use awk to generate a report. >> >> I'm working with a large data set spread across multiple files, but to >> keep things simple, say I have A Very Long String that containing records, >> each delimited by a single space. I need to print those records in >> columnar format, but with only 7 columns per line: >> >> record1 record2 record3 record4 record5 record6 record7 >> record08 record09 record10 record11 record12 record13 record14 >> ... > > A small sh script: > > #!/bin/sh > awk ' { > for (i=1; i<=NF; i++) { > printf("%s ", $i) > if (i % 7 == 0) { printf("\n") } > } > if (NF % 7 != 0) { printf("\n") } > } ' input An elegant solution if ever I read one. The mod operator should have been the first thing that came to mind. I'm not sure whether I need a class in remedial math, or remedial awk, but either way, my thanks for the solution.