免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 3920 | 回复: 12
打印 上一主题 下一主题

[文本处理] 关于切割日志的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2019-05-30 10:11 |只看该作者 |倒序浏览
用sed切割日志是可以把两个时间段的日志全部切割出来,可是如果两个时间点有一个不对就切割不到
用awk也可以切割日志,也可以做到相对精确,可是里面有一些日志分了几行,没有时间点的行要不就全部跟出来,要是设置了数字就全部没有,这个怎么解决呀


论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
2 [报告]
发表于 2019-05-30 13:15 |只看该作者
把你的写的sed和awk发出来看看,在发一段样本日志方便测试。

论坛徽章:
0
3 [报告]
发表于 2019-05-30 13:48 |只看该作者
回复 2# Shell_HAT

好的




论坛徽章:
0
4 [报告]
发表于 2019-05-30 16:59 |只看该作者
没有时间点的你不想要的话可以在执行awk时加入匹配模式,类似'/^\[/{if.......}'即可

论坛徽章:
0
5 [报告]
发表于 2019-05-30 17:09 |只看该作者
回复 4# leowang119

就是在两个时间点内的全部都要所以才会有问题!

论坛徽章:
0
6 [报告]
发表于 2019-05-30 17:10 |只看该作者
回复 2# Shell_HAT
[root@centos ~]# cat a
[2019-05-30 09:39:03.339] [DEBUG] [http-nio-8201-exec-2] [org.mybatis.spring.SqlSessionUtils] - Releasing transactional SqlSessio
[2019-05-30 09:39:03.339] [DEBUG] [http-nio-8201-exec-2] [org.mybatis.spring.SqlSessionUtils] - Transaction synchronization dereg
[2019-05-30 09:49:03.339] [DEBUG] [http-nio-8201-exec-2] [org.mybatis.spring.SqlSessionUtils] - Transaction synchronization closi
[2019-05-30 09:52:03.341] [DEBUG] [http-nio-8201-exec-2] [c.c.c.c.c.MasterSlaveRedisCacheServiceImpl] - redis del key=p2p_lock_Co
[2019-05-30 09:53:03.341] [ERROR] [http-nio-8201-exec-2] [c.c.core.aop.lock.TryLockAspect] - com.chuangjin.p2p.loan.exception.App
    at com.chuangjin.p2p.loan.service.FundRouter.packagingApplyFailMessage(FundRouter.java:321)
    at com.chuangjin.p2p.loan.service.FundRouter.route(FundRouter.java:206)
    at com.chuangjin.p2p.loan.service.FundRouter.routeAndUpdateContract(FundRouter.java:151)
    at com.chuangjin.p2p.loan.service.FundRouter$$FastClassBySpringCGLIB$$932cc0af.invoke(<generated>
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:656)
    at com.chuangjin.p2p.loan.service.FundRouter$$EnhancerBySpringCGLIB$$f56059c3.routeAndUpdateContract(<generated>
    at com.chuangjin.p2p.loan.service.impl.ContractServiceImpl.apply(ContractServiceImpl.java:756)
    at com.chuangjin.p2p.loan.service.impl.ContractServiceImpl$$FastClassBySpringCGLIB$$32198976.invoke(<generated>
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:9
    at com.chuangjin.core.aop.lock.TryLockAspect.tryLockAround(TryLockAspect.java:4
[2019-05-30 09:54:03.905] [DEBUG] [http-nio-8201-exec-4] [org.mybatis.spring.SqlSessionUtils] - Creating a new SqlSession
[2019-05-30 09:55:03.905] [DEBUG] [http-nio-8201-exec-4] [org.mybatis.spring.SqlSessionUtils] - Registering transaction synchroni
[2019-05-30 09:56:03.905] [DEBUG] [http-nio-8201-exec-4] [o.m.s.t.SpringManagedTransaction] - JDBC Connection [com.alibaba.druid.
[2019-05-30 09:56:03.905] [DEBUG] [http-nio-8201-exec-4] [c.c.p.l.d.C.countBorrowSuccessContract] - ==>  Preparing: select count(
[2019-05-30 09:57:03.905] [DEBUG] [http-nio-8201-exec-4] [c.c.p.l.d.C.countBorrowSuccessContract] - ==> Parameters: 133012(Long)
[2019-05-30 09:58:03.906] [DEBUG] [http-nio-8201-exec-4] [c.c.p.l.d.C.countBorrowSuccessContract] - <==      Total: 1
[2019-05-30 09:59:03.906] [DEBUG] [http-nio-8201-exec-4] [org.mybatis.spring.SqlSessionUtils] - Releasing transactional SqlSessio

论坛徽章:
0
7 [报告]
发表于 2019-05-30 17:12 |只看该作者
  1. [root@centos ~]# cat a
  2. [2019-05-30 09:39:03.339] [DEBUG] [http-nio-8201-exec-2] [org.mybatis.spring.SqlSessionUtils] - Releasing transactional SqlSessio
  3. [2019-05-30 09:39:03.339] [DEBUG] [http-nio-8201-exec-2] [org.mybatis.spring.SqlSessionUtils] - Transaction synchronization dereg
  4. [2019-05-30 09:49:03.339] [DEBUG] [http-nio-8201-exec-2] [org.mybatis.spring.SqlSessionUtils] - Transaction synchronization closi
  5. [2019-05-30 09:52:03.341] [DEBUG] [http-nio-8201-exec-2] [c.c.c.c.c.MasterSlaveRedisCacheServiceImpl] - redis del key=p2p_lock_Co
  6. [2019-05-30 09:53:03.341] [ERROR] [http-nio-8201-exec-2] [c.c.core.aop.lock.TryLockAspect] - com.chuangjin.p2p.loan.exception.App
  7.         at com.chuangjin.p2p.loan.service.FundRouter.packagingApplyFailMessage(FundRouter.java:321)
  8.         at com.chuangjin.p2p.loan.service.FundRouter.route(FundRouter.java:206)
  9.         at com.chuangjin.p2p.loan.service.FundRouter.routeAndUpdateContract(FundRouter.java:151)
  10.         at com.chuangjin.p2p.loan.service.FundRouter$FastClassBySpringCGLIB$932cc0af.invoke(<generated>)
  11.         at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
  12.         at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721)
  13.         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
  14.         at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java
  15.         at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.
  16.         at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
  17.         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
  18.         at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:656)
  19.         at com.chuangjin.p2p.loan.service.FundRouter$EnhancerBySpringCGLIB$f56059c3.routeAndUpdateContract(<generated>)
  20.         at com.chuangjin.p2p.loan.service.impl.ContractServiceImpl.apply(ContractServiceImpl.java:756)
  21.         at com.chuangjin.p2p.loan.service.impl.ContractServiceImpl$FastClassBySpringCGLIB$32198976.invoke(<generated>)
  22.         at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
  23.         at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721)
  24.         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
  25.         at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:9
  26.         at com.chuangjin.core.aop.lock.TryLockAspect.tryLockAround(TryLockAspect.java:48)
  27. [2019-05-30 09:54:03.905] [DEBUG] [http-nio-8201-exec-4] [org.mybatis.spring.SqlSessionUtils] - Creating a new SqlSession
  28. [2019-05-30 09:55:03.905] [DEBUG] [http-nio-8201-exec-4] [org.mybatis.spring.SqlSessionUtils] - Registering transaction synchroni
  29. [2019-05-30 09:56:03.905] [DEBUG] [http-nio-8201-exec-4] [o.m.s.t.SpringManagedTransaction] - JDBC Connection [com.alibaba.druid.
  30. [2019-05-30 09:56:03.905] [DEBUG] [http-nio-8201-exec-4] [c.c.p.l.d.C.countBorrowSuccessContract] - ==>  Preparing: select count(
  31. [2019-05-30 09:57:03.905] [DEBUG] [http-nio-8201-exec-4] [c.c.p.l.d.C.countBorrowSuccessContract] - ==> Parameters: 133012(Long)
  32. [2019-05-30 09:58:03.906] [DEBUG] [http-nio-8201-exec-4] [c.c.p.l.d.C.countBorrowSuccessContract] - <==      Total: 1
  33. [2019-05-30 09:59:03.906] [DEBUG] [http-nio-8201-exec-4] [org.mybatis.spring.SqlSessionUtils] - Releasing transactional SqlSessio
复制代码


论坛徽章:
0
8 [报告]
发表于 2019-05-30 17:38 |只看该作者
本帖最后由 jzsjm1002 于 2019-05-30 17:50 编辑

回复 7# vipty

楼主需求是这样吗?

123.png (59.02 KB, 下载次数: 110)

123.png

论坛徽章:
0
9 [报告]
发表于 2019-05-30 20:08 |只看该作者
回复 8# jzsjm1002

是的,可是sed切割日志一定要有第一个时间点,如果第一个时间点不能精确确定就没办法切割!

论坛徽章:
0
10 [报告]
发表于 2019-05-30 21:41 |只看该作者
回复 9# vipty

不能精确就用正则去匹配 通过分秒 来定位

123.png (69.89 KB, 下载次数: 103)

123.png
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP