免费注册 查看新帖 |

ChinaUnix.net

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 1091 | 回复: 12

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

论坛徽章:
0
发表于 2019-05-30 10:11 |显示全部楼层
用sed切割日志是可以把两个时间段的日志全部切割出来,可是如果两个时间点有一个不对就切割不到
用awk也可以切割日志,也可以做到相对精确,可是里面有一些日志分了几行,没有时间点的行要不就全部跟出来,要是设置了数字就全部没有,这个怎么解决呀


论坛徽章:
28
ChinaUnix元老
日期:2015-02-02 08:55:392017金鸡报晓
日期:2017-01-10 15:13:29CU十四周年纪念徽章
日期:2018-08-29 22:12:2715-16赛季CBA联赛之深圳
日期:2018-09-20 12:21:09
发表于 2019-05-30 13:15 |显示全部楼层
把你的写的sed和awk发出来看看,在发一段样本日志方便测试。

论坛徽章:
0
发表于 2019-05-30 13:48 |显示全部楼层
回复 2# Shell_HAT

好的
4.png
3.png
2.png
1.png

论坛徽章:
0
发表于 2019-05-30 16:59 |显示全部楼层
没有时间点的你不想要的话可以在执行awk时加入匹配模式,类似'/^\[/{if.......}'即可

论坛徽章:
0
发表于 2019-05-30 17:09 |显示全部楼层
回复 4# leowang119

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

论坛徽章:
0
发表于 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
发表于 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
发表于 2019-05-30 17:38 |显示全部楼层
本帖最后由 jzsjm1002 于 2019-05-30 17:50 编辑

回复 7# vipty

楼主需求是这样吗?

123.png

论坛徽章:
0
发表于 2019-05-30 20:08 |显示全部楼层
回复 8# jzsjm1002

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

论坛徽章:
0
发表于 2019-05-30 21:41 |显示全部楼层
回复 9# vipty

不能精确就用正则去匹配 通过分秒 来定位
123.png
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

ITPUB技术栈

ITPUB技术栈是ITPUB企业打造的垂直于IT领域的知识社群平台,在这里,你既可以是创作者也可以是消费者。如果你的IT生涯丰富多彩,喷薄的个人价值尽可在小栈内体现;如果你渴望找到志同道合的伙伴,拓宽人脉,小栈比跑会场更快。 小栈特色:
1.极高的用户转化率,实现更直接的知识变现;
2.随时随地,刷个朋友圈的时间,实现更长效的信息沉淀;
3.戳痛、难点的专业咨询,更接近成功解决方案的时刻;
4.贴近意见领袖,个人高速成长,迈入更富有价值的人际圈。

----------------------------------------

技术小栈>>
  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP