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