如何根据日期计算字符串的出现次数

时间:2013-09-19 15:28:48

标签: bash

我有这种格式的字符串

2013-06-13 17:07:10,449[MyThreadtest_1111] FATAL(Socket.java:<pushMessage>:288)- Exception on message ([["ddddd","NQ!COMP","COMP","0.00","0","0.00","0","3,445.37","0","0","0.00","3,451.03","3,387.61","+44.94","1.32%","u","----","3,398.54","0","0","e","null"],["S1","2G!SDS","SDS","39.53","5","39.55","5","39.54","250","14,042,322","14.04 M","41.02","39.40","-1.24","3.03%","d","1.92 B","40.85","0","0","e","null"],["S1","2G!SPY","SPY","164.22","23","164.23","10","163.38","1,000","148,798,711","148.80 M","164.50","161.30","+1.63","1.01%","u","136.92 B","161.65","0","0","e","null"],["S1","RU!RUT","RUT","0.00","0","0.00","0","989.69","0","0","0.00","990.87","969.79","+17.38","1.79%","u","----","971.75","0","0","e","null"]])::
java.io.IOException: Broken pipe
        at sun.nio.ch.FileDispatcher.write0(Native Method)
        at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:29)
        at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:100)
        at sun.nio.ch.IOUtil.write(IOUtil.java:56)
        at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
        at org.eclipse.jetty.io.nio.ChannelEndPoint.flush(ChannelEndPoint.java:230)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint.flush(SelectChannelEndPoint.java:292)

我想从2013-06-13 5到6之间的上述日志中搜索Broken pipe的出现次数

我试过这种方式

grep -c '^2013-06-13 05.*Broken pipe' mylog.log

但我得到0

1 个答案:

答案 0 :(得分:4)

grep -B1 "Broken pipe" mylog.log | grep -c "^2013-06-13 05"