From owner-freebsd-questions@FreeBSD.ORG Sun Nov 2 04:54:18 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 687C61065689 for ; Sun, 2 Nov 2008 04:54:18 +0000 (UTC) (envelope-from sahil@tandon.net) Received: from aegis.hamla.org (aegis.hamla.org [206.251.255.39]) by mx1.freebsd.org (Postfix) with ESMTP id 480AF8FC08 for ; Sun, 2 Nov 2008 04:54:18 +0000 (UTC) (envelope-from sahil@tandon.net) Received: from localhost (localhost [127.0.0.1]) by aegis.hamla.org (Postfix) with ESMTP id 8BF235C77 for ; Sun, 2 Nov 2008 00:55:16 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tandon.net; h= x-virus-scanned:in-reply-to:content-disposition:content-type :mime-version:references:reply-to:message-id:subject:from:date: received; s=aegis; t=1225601715; bh=mmzoC/w4c1Bwki0uuUslbx8UpFf9 4bvn0CkuN1nTPWI=; b=pVqmFN0bUrMw0z3xTQu2d/p5/voN+qxe3iQQ0oZ6nvRQ zdXfFjmbLTGWvSAsgLWXMVKXmyfS/N7+M8nRx6/Cx4d8nSE5NRGBjCriOV8yjG0N Ghc7ycRFX/G4e7Q3m4iPQBQHjKJ6LwLPgNWkMLVILkRBjQzS+IQoXZO0NLgpV7s= Received: from aegis.hamla.org ([127.0.0.1]) by localhost (aegis.hamla.org [127.0.0.1]) (amavisd-new, port 10027) with LMTP id 6rJjDDVQEfUr for ; Sun, 2 Nov 2008 00:55:15 -0400 (EDT) Date: Sun, 2 Nov 2008 00:54:15 -0400 From: Sahil Tandon To: freebsd-questions@freebsd.org Message-ID: <20081102045414.GA13745@shepherd> References: <2daa8b4e0811011821q210ae3a5j8f612a0fc79e8844@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2daa8b4e0811011821q210ae3a5j8f612a0fc79e8844@mail.gmail.com> X-Virus-Scanned: ClamAV version 0.94, clamav-milter version 0.94 on aegis.hamla.org X-Virus-Status: Clean Subject: Re: OT: Shell Script using Awk X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: "freebsd-questions@freebsd.org" List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Nov 2008 04:54:18 -0000 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 -- Sahil Tandon