Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

split mailbox one-liner

by japh (Friar)
on Mar 17, 2002 at 05:35 UTC ( #152279=snippet: print w/replies, xml ) Need Help??
Description: Split an mbox into numbered individual message files (for playing with spamassassin, in my case).
% perl -ne 'if(/^From /){open F,">msg".++$m}print F' mbox
Replies are listed 'Best First'.
Re: split mailbox one-liner
by merlyn (Sage) on Mar 17, 2002 at 18:27 UTC
    Not that we're golfing, but a "-n" loop that ends in "print" seems odd. {grin} I've used something like:
    perl -pe 'open STDOUT, ">out".++$n if /^From /' <in >before-first-outp +ut
    before, with the advantage that the original pre-first-From output ends up in a file that is not part of the series.

    -- Randal L. Schwartz, Perl hacker

      I'm trying to do something like this but instead of comparing it to From I'm comparing it to From:, but it doesn't seem to be working. Here's the code if ($line =~ /^From:\b/){whatever}
        That's because a normal "mailbox format" file isn't delimited by "From:"... it's delimited by "^From ". What kind of file do you have that might possibly be delimited by From:?

        -- Randal L. Schwartz, Perl hacker

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: snippet [id://152279]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2022-07-01 16:13 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (99 votes). Check out past polls.