Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 2 Nov 2008 14:50:31 +1000
From:      Gary Newcombe <gary@pattersonsoftware.com>
To:        "David Allen" <the.real.david.allen@gmail.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: OT: Shell Script using Awk
Message-ID:  <20081102145031.7d4e50aa.gary@pattersonsoftware.com>
In-Reply-To: <2daa8b4e0811012117i5d3f30d3w9ea927679cb5e7b1@mail.gmail.com>
References:  <2daa8b4e0811011821q210ae3a5j8f612a0fc79e8844@mail.gmail.com> <20081102020344.GA80530@icarus.home.lan> <2daa8b4e0811012117i5d3f30d3w9ea927679cb5e7b1@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 1 Nov 2008 20:17:54 -0800, "David Allen"
<the.real.david.allen@gmail.com> wrote:

> On 11/1/08, Jeremy Chadwick <koitsu@freebsd.org> wrote:
> > On Sat, Nov 01, 2008 at 06:21:55PM -0700, 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
> >> ...
> >>
> >> Should be simple, but I'm getting nowhere.
> >
> > $ cat input
> > col1 col2 col3 col4 col5 col6 col7 col8 col9 col10 col11 col12 col13 col14
> >
> > $ cat output.awk
> > {
> > 	print $1 " " $2 " "  $3 " "  $4 " "  $5 " "  $6 " "  $7
> > 	print $8 " " $9 " " $10 " " $11 " " $12 " " $13 " " $14
> > }
> >
> > $ cat intput | awk -f output.awk
> > col1 col2 col3 col4 col5 col6 col7
> > col8 col9 col10 col11 col12 col13 col14
> 

Maybe you want them to line up too. Would using tabs be appropriate?
Maybe something like this?

awk -F\  '{for (i=1;i<NF;i+=7) print $i "\t" $(i+1) "\t" $(i+2) "\t"
$(i+3) "\t" $(i+4) "\t" $(i+5) "\t" $(i+6) }' input



> Thanks for the reply, Jeremy, but that approach would require an
> entirely manual approach, which isn't suitable for what I'm working
> with.  Writing a script that's the same size as the data I'm working
> with isn't an option.  ;-)
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"



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