2015-12-22 78 views
-3

我得到了caffe的結果,我將從中提取最終的損失值。現在我已經用bash腳本獲得了最終結果。例如,輸出是:從bash腳本的Linux文本中獲取一些報告

I1221 15:29:03.581897 23416 solver.cpp:347] Iteration 300000, Testing net (#0) I1221 15:29:36.107956 23416 solver.cpp:415] Test net output #0: acc01 = 0.997557 I1221 15:29:36.108728 23416 solver.cpp:415] Test net output #1: acc02 = 0.799582 I1221 15:29:36.108815 23416 solver.cpp:415] Test net output #2: acc03 = 0.614063 I1221 15:29:36.108839 23416 solver.cpp:415] Test net output #3: acc04 = 0.875842 I1221 15:29:36.108880 23416 solver.cpp:415] Test net output #4: loss01 = 0.0183781 (* 1 = 0.0183781 loss) I1221 15:29:36.108914 23416 solver.cpp:415] Test net output #5: loss02 = 0.499269 (* 1 = 0.499269 loss) I1221 15:29:36.108945 23416 solver.cpp:415] Test net output #6: loss03 = 0.660662 (* 1 = 0.660662 loss) I1221 15:29:36.108974 23416 solver.cpp:415] Test net output #7: loss04 = 0.373288 (* 1 = 0.373288 loss) I1221 15:29:36.108996 23416 solver.cpp:332] Optimization Done. I1221 15:29:36.109011 23416 caffe.cpp:215] Optimization Done. 

,我會得到什麼:

300000, 0.997557, 0.799582, 0.614063, 0.875842, 0.0183781, 0.499269, 0.660662, 0.373288 

這是

Iteration, acc01, acc02, acc03, acc04, loss01, loss02, loss03, loss04 

請您指導我怎麼能寫一些bash腳本來做到這一點。

感謝, 阿夫欣

+0

看看'awk'文檔。這是可以用來做到這一點的工具之一。 –

+0

@ RichardSt-Cyr 非常感謝。有效。 –

回答

1

一個awk approach..hope你喜歡AWK!

awk -v value="" '{for(i=1;i<=NF;++i){if($i~/^acc/){value=value " " $(i+2)}else if($i~/^Iteration/){value=value $(i+1)}};print value}' my_file