grep & awk
- 打印匹配行的第二列
0.304443153 281764586 cycles
0.304443153 76724668 instructions
0.304443153 12055101 branch-instructions
grep cycles test.txt | awk '{print $2}'
281764586
- grep 完全匹配
grep -w “word”
- awk計算平均值,最大值,最小值
apuser@BJ08491PCU01:~/task/bug1145345/perf$ cat test.txt | head -10
# started on Tue Aug 27 09:18:25 2019# time counts unit events
求平均值
0.304443153 281764586 cycles
0.304443153 76724668 instructions
0.304443153 12055101 branch-instructions
0.304443153 2004530 branch-misses
0.304443153 22436839 cache-references
0.304443153 1346060 cache-misses
0.609641384 291220773 cyclesgrep -w "branch-instructions" test.txt | awk '{print $2}'| awk '{sum+=$1}END{print "Average = ", sum/NR}'
awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print "Max=", max}'
awk 'BEGIN {min = 6553565} {if ($1<min) min=$1 fi} END {print "Min=", min}'
awk '{sum+=$1} END {print "Sum = ", sum}'
- awk計算平均值,最大值,最小值