2017-05-05 126 views
0

我有一個示例jtl文件,如下所示: 我必須讀取每個操作所花費的時間,如JR_ *所示,time is in t =「」from the latest 10 jtl文件,並計算平均值。 我試圖做一個shell腳本,會做計算特定操作的平均水平在過去10次的這種具體行動,(閱讀最新的10 JTL文件)Shell腳本來解析最近10次運行的JTL文件

<sample t="5203" it="0" lt="0" ts="1493818151051" s="true" lb="JR_READ" rc="200" rm="OK" tn="Thread Group 1-2" dt="text" by="0" ng="2" na="2"/> 
<sample t="3584" it="0" lt="0" ts="1493818151660" s="true" lb="JR_WRITE" rc="200" rm="OK" tn="Thread Group 1-2" dt="text" by="0" ng="2" na="2"/> 
<sample t="61280" it="0" lt="0" ts="1493818152265" s="true" lb="JR_SAVE" rc="200" rm="OK" tn="Thread Group 1-2" dt="text" by="0" ng="2" na="2"/> 
<sample t="129935" it="0" lt="0" ts="1493818152870" s="true" lb="JR_DELETE" rc="200" rm="OK" tn="Thread Group 1-2" dt="text" by="0" ng="2" na="2"/> 

我想這樣一些事:

#!/bin/sh 
cd /tests/unit/ 
fNames=$(ls -t | grep -i jenkins-TEST_UNIT | head -n 10) 
#printf "%s\n" "${fNames[@]}" 
## now loop through the above array 
for i in "${fNames[@]}" 
do 
    #echo "$i" 
    grep -I "JR_READ" $i/Summary.jtl | awk -F '"' '{print $2}' 
    # or do whatever with individual element of the array 
done 

我得到的「時間」作爲需要的只有一個文件,目錄,我得到這個錯誤,這可能是原因的休息嗎? grep只適用於一個文件。

grep: jenkins-TEST_UNIT12: Is a directory 
grep: jenkins-TEST_UNIT9: Is a directory 
grep: jenkins-TEST_UNIT8: Is a directory 
grep: jenkins-TEST_UNIT7: Is a directory 
grep: jenkins-TEST_UNIT6: Is a directory 
grep: jenkins-TEST_UNIT5: Is a directory 
grep: jenkins-TEST_UNIT4: Is a directory 
grep: jenkins-TEST_UNIT3: Is a directory 
grep: jenkins-TEST_UNIT2: Is a directory 
60665 

想法表示歡迎,感謝

+0

該輸出你已經發布,它是一個單一的JTL文件內容?你能提供更多細節嗎? – RomanPerekhrest

+0

你爲自己嘗試了什麼 – Inian

+0

awk是這種shell操作的好工具。使用't = $ 2; gsub(/^[^「] *」|「$ /,」「; t)'獲得每行的時間(與$ 7操作類似) – NeronLeVelu

回答