Reputation: 342
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]>
Upvotes: 1
Views: 173
Reputation: 3125
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.
Upvotes: 1