bash - shell脚本解析日志文件

标签 bash shell sed awk grep

我得到了一个日志文件(见下文),我需要使用 bash 脚本将其设置为这种格式:

 
title pdfspool date rip date bmpspool date CLAB date Sometitle12 10/09/23 00:56:40 10/9/23 0:56:46 10/9/23 0:56:50 10/9/23 1:01:13

日志文件


!!Begin    
Source aserver:pdf_spool:the, Job 844b015e0043469e, Inst 844b015e0043469e    
Title Sometitle12.pdf    
Action Started Received, Ok Date 10/09/23 00:56:40    
For Administrator    
(8) DataType = PDF    
(17) Source = srv01:aserver:file_input:0    
!!End    
!!Begin    
Source aserver:rip:rip1, Job 844b015e0043469e, Inst 844b015e004346a0    
Title Sometitle12.pdf Cyan 1    
Action Started Transmit, Ok Date 10/09/23 00:56:46    
For Administrator    
(8) DataType = Bitmap    
(1) Destination = srv01:bserver:bmp_spool:the    
(4) Parent = 844b015e0043469e/844b015e0043469e    
!!End    
!!Begin    
Source bserver:bmp_spool:the, Job 844b015e0043469e, Inst 844b015e004346a0    
Title Sometitle12.pdf Cyan 1    
Action Started Received, Ok Date 10/09/23 00:56:50    
For Administrator    
(8) DataType = Bitmap    
(17) Source = srv01:aserver:rip:rip1    
!!End    
!!Begin    
Source bserver:bmp_spool:the, Job 844b015e0043469e, Inst 844b015e004346a0    
Title Sometitle12.pdf Cyan 1    
Action Atomic Accepted, Ok Date 10/09/23 01:01:13    
For Administrator    
(8) DataType = Bitmap    
(2) Source Queue = ^03Newspaper ltd(MP)^Date - 24MP^Site - N^    
(5) Requested By = clab    
(15) Approval Status = Waiting Approved    
 Changed from Waiting to Approved by clab.   
!!End    

欢迎提出想法。

谢谢!

最佳答案

awk 'BEGIN{}
/Action Started Received/ && !c{ pdfspooldate=$(NF-1)$NF ;c++}
/Action Started Received/ && c{ bmppooldate=$(NF-1)$NF ;c=0}
/Action Started Transmit/{ ripdate=$(NF-1)$NF }
/title/ { title=$2}
/Action Atomic Accepted/{ clabdate=$(NF-1)$NF }
END{ print title,pdfspooldate,ripdate,clabdate }' file

关于bash - shell脚本解析日志文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3974679/

相关文章:

linux - 使用 eval '$cmd' 执行变量将产生错误

shell - Applescript 操作 VLC

linux - 如何将我的 sed 命令应用于我所有文件的某些行?

ubuntu - 尝试使用 sed 将温度从传感器命令转换为数字

macos - iTerm2 右大括号不起作用

bash - 多行 perl 正则表达式在没有 slurp 的情况下替换大文件

bash - 如何通过 ssh 解压多个 tar 文件?

python - 从python获取java版本号

java - 如何在java中运行异步bash命令?

bash - 如何从 "permission denied"中排除所有 "find"消息?