使用shell计算模式出现次数

时间:2016-01-13 23:47:28

标签: shell awk sed

我有一个生成的跟踪,想要根据shell命令awksed进行一些简单的分析。跟踪的格式为:

../filter_on/2016-01-11--22.24.30/ruby/observ/out/observ_jruby_optimalj9_OUT:11/Jan/2016:22:50:03:941  java.lang.invoke.ReceiverBoundHandle  MethodHandle(ThreadContext)IRubyObject
../filter_on/2016-01-11--22.24.30/ruby/printff/out/printff_jruby_optimalj9_OUT:11/Jan/2016:22:29:30:585  java.lang.invoke.ReceiverBoundHandle  null
../filter_on/2016-01-11--22.24.30/ruby/printff/out/printff_jruby_optimalj9_OUT:11/Jan/2016:22:29:30:586  java.lang.invoke.PermuteHandle  null
../filter_on/2016-01-11--22.24.30/ruby/cal/out/cal_jruby_optimalj9_OUT:11/Jan/2016:22:54:17:683  java.lang.invoke.ReceiverBoundHandle  null
../filter_on/2016-01-11--22.24.30/ruby/cal/out/cal_jruby_optimalj9_OUT:11/Jan/2016:22:54:17:684  java.lang.invoke.ReceiverBoundHandle  null

我的预期输出是表格:

observ   ReceiverBoundHandle  MethodHandle(ThreadContext)IRubyObject   1
printff  PermuteHandle        null             1
printff  ReceiverBoundHandle  null    1  
cal      ReceiverBoundHandle  null    2

最后一列是看到前三列的时间。

1 个答案:

答案 0 :(得分:0)

我正在使用awksortuniq。如果你可以忍受这个并且重复的计数器是第一列而不是最后一列,那么这应该做:

cat trace | awk -F "[/ ]+" '{print $5"\t"$10"\t"$11}' | sort | uniq -c

输入文件的输出如下:

  2 cal     java.lang.invoke.ReceiverBoundHandle    null
  1 observ  java.lang.invoke.ReceiverBoundHandle    MethodHandle(ThreadContext)IRubyObject
  1 printff java.lang.invoke.PermuteHandle  null
  1 printff java.lang.invoke.ReceiverBoundHandle    null