看板 Perl 關於我們 聯絡資訊
不好意思請教一個問題 我的input file類似這樣 這是cacti的output file Total Cache Size: 131072 Associativity: direct mapped Block Size (bytes): 128 Technology Size: 0.07um Access Time (ns): 0.719224 Cycle Time (ns): 0.318145 Total dynamic Read Energy all Banks (nJ): 0.0201788 Total dynamic Write Energy all Banks (nJ): 0.00375056 Total leakage Read/Write Power Without Routing (mW): 452.626 如果我要找到"Access Time (ns):" 然後print出0.719224 不知該用哪個語法呢? 感激不盡~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 67.79.77.75
play9091:open(name,"filename.txt") 04/27 14:30
play9091:for $line (<name>){ 04/27 14:32
play9091: if (line =~ m/Access Time/){ 04/27 14:33
play9091: @sline = split(' ',$line); 04/27 14:35
play9091: print "$sline[3]\n"; 04/27 14:36
play9091: } 04/27 14:37
play9091:} 04/27 14:37
play9091:Sorry,第一行的行末沒有加上分號 " ; " 04/27 14:38
play9091:第三行的 " line " 改為 " $line " 04/27 14:38
play9091:最近在寫 Python , Perl 反而有點生了! 04/27 14:41
japanet:感謝不盡~ 04/28 13:00
japanet:可以再請教如何讀多個檔案進來跑這個for loop呢? 04/28 13:06
play9091:要多加檔案的話要改寫吧!您有寫過Perl嗎? 04/28 17:31
play9091:外面再包一個LOOP,或是另外一種寫法…… 04/28 17:31
pshuang:print `cat file | grep "Access Time" |cut -d ":" -f 3` 05/03 18:08
pshuang:用perl來處裡shell最擅長的事,不會很累嗎? 05/03 18:09
pshuang:要多個檔案 把cat file 中 file 改成變數就好 05/03 18:11
HowLeeHi:不用多一道cat手續,直接 grep "Access Time" file省時 05/29 17:50
HowLeeHi:然後cut -d ":" -f 2 05/29 17:52