使用shell计算模式出现次数

使用shell计算模式出现次数,shell,awk,sed,Shell,Awk,Sed,我有一个生成的跟踪,希望基于shell命令awk和sed进行一些简单的分析。跟踪的格式为: ../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-

我有一个生成的跟踪,希望基于shell命令
awk
sed
进行一些简单的分析。跟踪的格式为:

../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

最后一列是前三列的显示时间

我使用的是
awk
sort
uniq
。如果您可以接受这一点,并且重复计数器是第一列而不是最后一列,那么这应该可以:

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