1

I am currently storing below lines in a file named google.txt. I want to seperate these lines and store those seperated strings in arrays.

Like for first line

@qf_file= q33AgCEv006441  
@date =    Tue Apr  3 16:12
@junk_message = User unknown
@rf_number = [email protected]

the line ends at the @rf_number at last emailadress
   q33AgCEv006441     1038 Tue Apr  3 16:12 <[email protected]>
                     (User unknown)
                     <[email protected]>
    q33BDrP9007220    50153 Tue Apr  3 16:43 <[email protected]>
                     (Deferred: 451 4.2.1 mailbox temporarily disabled: paond.tndt)
                      <[email protected]>
    q33BDrPB007220    50153 Tue Apr  3 16:43 <[email protected]>
                     (User unknown)
                     [email protected]>
                                             <[email protected]>
                                             <[email protected]>
    q33BDrPA007220    50153 Tue Apr  3 16:43 <[email protected]>
                     (User unknown)
                     <[email protected]>
                     <[email protected]>
    q2VDWKkY010407  2221878 Sat Mar 31 19:37 <[email protected]>
                     (host map: lookup (now-india.net.in): deferred)
                     <[email protected]>
    q2VDWKkR010407  2221878 Sat Mar 31 19:31 <[email protected]>
                     (host map: lookup (aaplawoffices.in): deferred)
                      <[email protected]>
    q2U8qZM7026999   360205 Fri Mar 30 14:38 <[email protected]>
                     (host map: lookup (now-india.net.in): deferred)
                      <[email protected]>
                       <[email protected]>
    q2TEWWE4013920  2175270 Thu Mar 29 20:30 <[email protected]>
                     (host map: lookup (now-india.net.in): deferred)
                               <[email protected]>
                               <[email protected]>
3
  • 2
    Do you have any code written? It's Stack Overflow etiquette to start some code and/or show what you have tried. Commented May 31, 2012 at 16:46
  • Also, could you clarify where the actual line endings are? You say the "first line", but reference the first 3 apparent lines in the code block... Commented May 31, 2012 at 16:51
  • If there are multiple emails, which one goes in @rf_number? Commented May 31, 2012 at 17:09

1 Answer 1

1

Untested Perl script:

Let's call this script parser.pl:

$file = shift;
open(IN, "<$file") or die "Cannot open file: $file for reading ($!)\n";
while(<IN>) {
    push(@qf_file, /^\w+/g); 
    push(@date, /(?:Sat|Sun|Mon|Tue|Wed|Thu|Fri)[\w\s:]+/g);
    push(@junk_message, /(?<=\().+(?=\)\s*<)/g);
    push(@rf_number, /(?<=<)[^>]+(?=>\s*$)/g);
}
close(IN);

This assumes the last email on the line should be the "rf_number" for that line. Note that emails may be tricky to print, as they have an @ character, and perl is more than happy to print a non-existent list for you :-)

To call this in a command line:

parser.pl google.txt

See this working here.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Kevlar for working on it really appreciate it ill look into the script right now
If you haven't tested it for your needs, don't accept the answer... You probably should just +1 it if you feel like its helped before accepting it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.