作者:
japanet (電機模範生)
2013-04-27 13:18:36不好意思請教一個問題
我的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
不知該用哪個語法呢?
感激不盡~
作者: play9091 (長工) 2013-04-27 14:30:00
open(name,"filename.txt")for $line (<name>){if (line =~ m/Access Time/){@sline = split(' ',$line);print "$sline[3]\n";}}Sorry,第一行的行末沒有加上分號 " ; "第三行的 " line " 改為 " $line "最近在寫 Python , Perl 反而有點生了!
作者: japanet (電機模範生) 2013-04-28 13:00:00
感謝不盡~可以再請教如何讀多個檔案進來跑這個for loop呢?
作者: play9091 (長工) 2013-04-28 17:31:00
要多加檔案的話要改寫吧!您有寫過Perl嗎?外面再包一個LOOP,或是另外一種寫法……
作者:
pshuang (中山先生忠實信徒-我愛蘿)
2013-05-03 18:08:00print `cat file | grep "Access Time" |cut -d ":" -f 3`用perl來處裡shell最擅長的事,不會很累嗎?要多個檔案 把cat file 中 file 改成變數就好
作者:
HowLeeHi (處處留心皆正妹)
2013-05-29 17:50:00不用多一道cat手續,直接 grep "Access Time" file省時然後cut -d ":" -f 2