小编mar*_*rco的帖子

按日期合并多个日志文件,包括多行

我有几个日志包含所有以时间戳开头的行,以便以下工作按预期合并它们:

cat myLog1.txt myLog2.txt | sort -n > combined.txt
Run Code Online (Sandbox Code Playgroud)

问题是,myLog2.txt还可以包含没有时间戳的行(例如java堆栈跟踪).是否有一种简单的方法,没有任何自定义脚本仍然合并它们并保留多行内容?

示例myLog1.txt

11:48:18.825 [main] INFO  org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
11:48:55.784 [main] INFO  o.h.tool.hbm2ddl.SchemaUpdate - HHH000396: Updating schema
Run Code Online (Sandbox Code Playgroud)

示例myLog2.txt

11:48:35.377 [qtp1484319352-19] ERROR c.w.b.c.ControllerErrorHandler -
org.springframework.beans.TypeMismatchException: Failed to convert value of type   'java.lang.String' to required type 'org.joda.time.LocalDate'; nested exception is    org.springframework.core.convert.ConversionFailedException: Failed to convert from type     java.lang.String to type @org.springframework.web.bind.annotation.RequestParam   @org.springframework.format.annotation.DateTimeFormat org.joda.time.LocalDate for value    '[2013-03-26]'; nested exception is java.lang.IllegalArgumentException: Invalid format: "    [2013-03-26]"
    at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:68) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:45) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE] …
Run Code Online (Sandbox Code Playgroud)

sorting logging command-line log-files cat

10
推荐指数
1
解决办法
8380
查看次数

标签 统计

cat ×1

command-line ×1

log-files ×1

logging ×1

sorting ×1