public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: Etaoin Shrdlu <shrdlu@unlimitedmail.org>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] [OT] - command line read *.csv & create new file
Date: Sun, 22 Feb 2009 23:57:39 +0100	[thread overview]
Message-ID: <200902222357.40242.shrdlu@unlimitedmail.org> (raw)
In-Reply-To: <5bdc1c8b0902221428i4f8fd44ev5c0bd249bb157c72@mail.gmail.com>

On Sunday 22 February 2009, 23:28, Mark Knecht wrote:

> > <concatenation of attributes of lines 1..n> <result of line n>
> > <concatenation of attributes of lines 2..n+1> <result of line n+1>
> > <concatenation of attributes of lines 3..n+2> <result of line n+1>
> > <concatenation of attributes of lines 4..n+3> <result of line n+1>
>
> The above diagram is correct when the lines chosen is 3. I suspect
> that I might chose 10 or 15 lines once I get real data and do some
> testing but that was harder to show in this email. A good design for
> me would be a single variable I could set. Once a value is chosen I
> want to process every line in the input file the same way. I don't use
> 5 lines sometimes and 10 lines other times. In a given file it's
> always the same number of lines.

Ok, try this for a start:

BEGIN { FS=OFS=","}

{
  r=$NF;NF--
  for(i=1;i<n;i++){
    s[i]=s[i+1]
    if(NR>=n)printf "%s%s",s[i],OFS
  }
  s[n]=$0;if(NR>=n)printf "%s,%s\n", s[n],r
}

Save the above code in a file (eg, program.awk) and run it with

awk -v n=3 -f program.awk datafile.csv

where the "n=3" part is to  be replaced with the actual number of lines 
you want to group (eg, n=5, n=4, etc.)

With your sample input and n=3, the above awk program produces the output 
you show.



  reply	other threads:[~2009-02-22 22:59 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-22 19:06 [gentoo-user] [OT] - command line read *.csv & create new file Mark Knecht
2009-02-22 20:15 ` Etaoin Shrdlu
2009-02-22 22:28   ` Mark Knecht
2009-02-22 22:57     ` Etaoin Shrdlu [this message]
2009-02-22 23:31       ` Mark Knecht
2009-02-23  6:17         ` Paul Hartman
2009-02-23  9:57         ` Etaoin Shrdlu
2009-02-23 16:05           ` Mark Knecht
2009-02-23 22:18             ` Etaoin Shrdlu
2009-02-24  2:26               ` Mark Knecht
2009-02-24 10:56                 ` Etaoin Shrdlu
2009-02-24 14:41                   ` Mark Knecht
2009-02-24 17:48                     ` Etaoin Shrdlu
2009-02-24 22:51                       ` Mark Knecht
2009-02-25 10:27                         ` Etaoin Shrdlu
2009-02-22 20:59 ` Willie Wong
2009-02-22 23:15   ` Mark Knecht
2009-02-23  0:57     ` Willie Wong
2009-02-23  1:54       ` Mark Knecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200902222357.40242.shrdlu@unlimitedmail.org \
    --to=shrdlu@unlimitedmail.org \
    --cc=gentoo-user@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox