2012-05-31 34 views
1

我目前在一個名爲google.txt的文件中存儲了以下行。我想分離這些行並將這些分離的字符串存儲在數組中。將字符串存儲在一個數組中

像第一行

@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]> 
+2

你有寫的任何代碼嗎?它是堆棧溢出禮儀來啓動一些代碼和/或顯示你已經嘗試過的東西。 – kevlar1818

+0

另外,你能澄清實際的行結局在哪裏嗎?你說的是「第一行」,但引用代碼塊中的前3個明顯行... – kevlar1818

+0

謝謝凱夫拉我編輯帖子,請參閱 –

回答

1

未經測試 Perl腳本:

讓我們把這個腳本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); 

這假定行上的最後一封電子郵件應該是該行的「rf_number」。請注意,電子郵件可能會非常棘手打印,因爲他們有一個@性格,Perl是更樂意打印一個不存在的列表供您:-)

要在命令行調用這個:

parser.pl google.txt 

看到這個工作here

+0

感謝Kevlar對它的工作感到非常欣慰現在看不到它 –

+1

如果你還沒有根據你的需求對它進行測試,請不要接受答案......如果你喜歡它,你可能應該只是+1接受之前幫助。 – kevlar1818

+0

這是否最終爲你工作? – kevlar1818

相關問題