Please excuse the NOOB question - go easy on me please~!

Discussion in 'Perl Misc' started by GlenM, Feb 25, 2010.

  1. GlenM

    GlenM Guest

    Okay;

    I am sure that someone out there has done this before - I *think* I am
    on the right track.

    I have a directory full of emails. What I would like to do is read
    each file in, then parse them into a CSV style file.

    Example:


    #!/usr/bin/perl

    use warnings;
    use strict;

    open FILE , "/home/gmillard/SentMail/YourSatSetup.txt" or die $!;
    my $linenum =1;

    while (<FILE>) {
    print "|", $linenum++;
    print"$_" ;
    }

    Produces the following.

    |1From - Sun Feb 21 11:40:01 2010
    |2X-Mozilla-Status: 0001
    |3X-Mozilla-Status2: 00000000
    |4X-Gmail-Received: 58fa0ec68ca9975c1d187ceadc0ad3aeb1026134
    |5Received: by 10.48.212.6 with HTTP; Fri, 17 Nov 2006 12:52:26 -0800
    (PST)
    |6Message-ID:
    <>
    |7Date: Fri, 17 Nov 2006 15:52:26 -0500
    |8From: "xxxxxxxxxxxxxxxxxxxxxxxx>
    |9To:
    |10Subject: Your satellite set up. . From an article that i read.
    |11MIME-Version: 1.0
    |12Content-Type: text/plain; charset=ISO-8859-1; format=flowed
    |13Content-Transfer-Encoding: 7bit
    |14Content-Disposition: inline
    |15Delivered-To: xxxxxxxxxxxxxxxxxxxxxx
    |16
    |17Hi Andrew;
    |18I read an article about you a while back about your MythTV and VOip
    |19setup. Would you mind if i asked you some tech questions ? I am
    very
    |20intrigued.
    |21Thanks
    |22Glen xxxxxxxxxx
    |23xxxxxxxxxxxxx


    I have hundreds of emails in this directory. I would like to parse
    them into a single file where each comma separated/tab separated field
    is a line from the email.

    So, the first line of the CSV file is
    |1From - Sun Feb 21 11:40:01 2010|2X-Mozilla-Status: 0001|3X-Mozilla-
    Status2: 00000000|4X-Gmail-Received:
    58fa0ec68ca9975c1d187ceadc0ad3aeb1026134
    <truncated>

    and each subsequent line is the next email and so forth.

    Any words of wisdom?

    Thanks much.

    Glen
     
    GlenM, Feb 25, 2010
    #1
    1. Advertising

  2. GlenM

    GlenM Guest

    Parsing many emails (text files) into a CSV -type file - would likesome words of wisdom please.

    On Feb 25, 2:14 pm, Tad McClellan <> wrote:
    > GlenM <> wrote:
    > > Subject: Please excuse the NOOB question - go easy on me please~!

    >
    > Please put the subject of your article in the Subject of your article.
    >
    > --
    > Tad McClellan
    > email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
     
    GlenM, Feb 25, 2010
    #2
    1. Advertising

  3. Tad McClellan wrote:
    > GlenM <> wrote:
    >
    >> Subject: Please excuse the NOOB question - go easy on me please~!

    >
    >
    > Please put the subject of your article in the Subject of your article.

    Being mean to newbies is not a good way to
    promote the use of perl.
    Got it!?!?
     
    Richard McBeef, Feb 25, 2010
    #3
  4. GlenM

    Uri Guttman Guest

    >>>>> "RM" == Richard McBeef <> writes:

    RM> Tad McClellan wrote:
    >> GlenM <> wrote:
    >>
    >>> Subject: Please excuse the NOOB question - go easy on me please~!

    >>
    >>
    >> Please put the subject of your article in the Subject of your article.

    RM> Being mean to newbies is not a good way to
    RM> promote the use of perl.
    RM> Got it!?!?

    no, teaching a newbie how to best ask a question is helping him. your
    flaming a regular here and not addressing the newbie question is less
    helpful. so please flame yourself for that. got it?!?!

    uri

    --
    Uri Guttman ------ -------- http://www.sysarch.com --
    ----- Perl Code Review , Architecture, Development, Training, Support ------
    --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
     
    Uri Guttman, Feb 25, 2010
    #4
  5. GlenM

    Steve C Guest

    Richard McBeef wrote:
    > Tad McClellan wrote:
    >> GlenM <> wrote:
    >>
    >>> Subject: Please excuse the NOOB question - go easy on me please~!

    >>
    >>
    >> Please put the subject of your article in the Subject of your article.

    > Being mean to newbies is not a good way to
    > promote the use of perl.
    > Got it!?!?
    >


    Since when is saying please "Being mean"? It's a valid correction.
    The subject of this thread is NOOB question, not promoting the use of perl.
     
    Steve C, Feb 25, 2010
    #5
  6. GlenM wrote:
    > Okay;
    >
    > I am sure that someone out there has done this before - I *think* I am
    > on the right track.
    >
    > I have a directory full of emails. What I would like to do is read
    > each file in, then parse them into a CSV style file.
    >
    > Example:
    >
    >
    > #!/usr/bin/perl
    >
    > use warnings;
    > use strict;
    >
    > open FILE , "/home/gmillard/SentMail/YourSatSetup.txt" or die $!;
    > my $linenum =1;
    >
    > while (<FILE>) {
    > print "|", $linenum++;
    > print"$_" ;
    > }
    >
    > Produces the following.
    >
    > |1From - Sun Feb 21 11:40:01 2010
    > |2X-Mozilla-Status: 0001
    > |3X-Mozilla-Status2: 00000000
    > |4X-Gmail-Received: 58fa0ec68ca9975c1d187ceadc0ad3aeb1026134
    > |5Received: by 10.48.212.6 with HTTP; Fri, 17 Nov 2006 12:52:26 -0800
    > (PST)
    > |6Message-ID:
    > <>
    > |7Date: Fri, 17 Nov 2006 15:52:26 -0500
    > |8From: "xxxxxxxxxxxxxxxxxxxxxxxx>
    > |9To:
    > |10Subject: Your satellite set up. . From an article that i read.
    > |11MIME-Version: 1.0
    > |12Content-Type: text/plain; charset=ISO-8859-1; format=flowed
    > |13Content-Transfer-Encoding: 7bit
    > |14Content-Disposition: inline
    > |15Delivered-To: xxxxxxxxxxxxxxxxxxxxxx
    > |16
    > |17Hi Andrew;
    > |18I read an article about you a while back about your MythTV and VOip
    > |19setup. Would you mind if i asked you some tech questions ? I am
    > very
    > |20intrigued.
    > |21Thanks
    > |22Glen xxxxxxxxxx
    > |23xxxxxxxxxxxxx
    >
    >
    > I have hundreds of emails in this directory. I would like to parse
    > them into a single file where each comma separated/tab separated field
    > is a line from the email.
    >
    > So, the first line of the CSV file is
    > |1From - Sun Feb 21 11:40:01 2010|2X-Mozilla-Status: 0001|3X-Mozilla-
    > Status2: 00000000|4X-Gmail-Received:
    > 58fa0ec68ca9975c1d187ceadc0ad3aeb1026134
    > <truncated>
    >
    > and each subsequent line is the next email and so forth.
    >
    > Any words of wisdom?


    UNTESTED:

    #!/usr/bin/perl
    use warnings;
    use strict;

    local @ARGV = glob "/home/gmillard/SentMail/*.txt";

    while ( <> ) {
    chomp;
    print "|$.$_";
    if ( eof ) {
    close ARGV;
    print "\n";
    }
    }




    John
    --
    The programmer is fighting against the two most
    destructive forces in the universe: entropy and
    human stupidity. -- Damian Conway
     
    John W. Krahn, Feb 25, 2010
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mike
    Replies:
    4
    Views:
    4,284
    Gordon Beaton
    May 12, 2004
  2. mike
    Replies:
    3
    Views:
    392
    Paul Lutus
    Sep 10, 2004
  3. mike
    Replies:
    4
    Views:
    435
  4. Andrey Koptyaev

    please point me or just excuse for may be spam

    Andrey Koptyaev, Sep 29, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    277
    Andrey Koptyaev
    Sep 29, 2006
  5. Andrey Koptyaev
    Replies:
    7
    Views:
    497
    Andrey Koptyaev
    Oct 2, 2006
Loading...

Share This Page