Search the web
Sign In
New User? Sign Up
geeksthatgawk · for GNU Awk questions & discussions
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Re: [Geeks that Gawk] msplit   Message List  
Reply | Forward Message #50 of 221 |
Re: [Geeks that Gawk] msplit

----- 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



Thu Dec 12, 2002 7:03 am

peter_tillier
Offline Offline
Send Email Send Email

Forward
Message #50 of 221 |
Expand Messages Author Sort by Date

... 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...
Peter S Tillier
peter_tillier
Offline Send Email
Dec 11, 2002
9:06 pm

... You are the geek! :) It worked exactly like "msplit.pl". I made some modifications. Code follows: #!/bin/awk # msplit splits a unix mailbox file into many...
Daniel Ajoy
daniel_ajoy
Offline Send Email
Dec 12, 2002
5:21 am

... 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...
Peter S Tillier
peter_tillier
Offline Send Email
Dec 12, 2002
7:03 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help