----- Original Message -----
From: "Daniel Ajoy" <dajoy@...>
To: <geeksthatgawk@yahoogroups.com>
Cc: <awk@yahoogroups.com>
Sent: Thursday, December 12, 2002 5:21 AM
Subject: Re: [Geeks that Gawk] msplit
> On 11 Dec 2002 at 21:06, Peter S Tillier wrote:
>
> > Literal translation follows (untested):
> >
>
> You are the geek! :)
> It worked exactly like "msplit.pl".
Good!
> I made some modifications. Code follows:
>
>
> #!/bin/awk
>
> # msplit splits a unix mailbox file into many separate files.
> # msplit.awk
> # Run as:
> # msplit.awk filename num prefix suffix
>
> BEGIN {
> num = ARGV[2]
> prefix = ARGV[3]
> suffix = ARGV[4]
You ought to delete ARGV[2] to ARGV[4] once you've copied the
values that you need - otherwise awk will try to open files
that have names that are the same as the values of num, prefix
and suffix.
> ofile = prefix sprintf("%04d",filenum) suffix
> }
>
> /^From / {
> nmsgs ++
> if (nmsgs > num) {
> filenum++
> ofile = prefix sprintf("%04d",filenum) suffix
> close(ofile)
> nmsgs = 0
> }
> }
>
> { print > ofile }
>
This is a more "awk-like" solution but I was a little pushed
for time when I posted the earlier solution.
> Daniel
>
> PS. I'm not sure how the "num" argument can be used...
Suppose you run it like this:
$ awk -f msplit.awk mailfile 30 mail .splt
It will create files containing up to 30 messages each, with
names like mail0000.splt, mail0001.splt, and so on. If you
don't delete ARGV[2] to ARGV[4] then the code will try to
open and read from files called 30, mail and .splt
Regards,
Peter
__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com