简体   繁体   English

使用awk命令格式化日志

[英]Log formatting using awk command

Log file has thousands of lines generated in below format.. 日志文件具有以以下格式生成的数千行。

05:34:11,447 DEBUG [com.ibm.cmps.beer.web.action.BlastApp]  deliveryConstant FTP is completed

To simplify, My Log text file has data in following format 为简化起见,“我的日志”文本文件具有以下格式的数据

d1 o1 c1 message1
d1 o1 c1 message2
d1 o1 c1 message3
d1 o1 c2 message4
d1 o1 c2 message5
d1 o1 c3 message6
d1 o1 c4 message7
d1 o1 c5 message8

To display only classnames(c1,c2,...) and messages, I use below command to drop column 1 & 2- 要仅显示类名(c1,c2,...)和消息,我使用以下命令删除第1列和第2列

awk '{$1=$2="";print $0}' file.log

As log file is very large, I want to filter log in below format- 由于日志文件非常大,我想按以下格式过滤日志-

c1  message1
    message2
    message3
c2  message4
    message5
c3  message6
c4  message7
c5  message8

I wish to skip repeated class names or replace it with space. 我希望跳过重复的类名或将其替换为空格。

Thanks! 谢谢!

awk '!a[$3]{printf $3; a[$3]=1} {print "\t"$4}' File

Output: 输出:

c1      message1
        message2
        message3
c2      message4
        message5
c3      message6
c4      message7
c5      message8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM