当前位置: > shell编程 >

使用awk整理日志格式的代码

时间:2014-06-19 13:28来源:linux.it.net.cn 作者:IT网
文本如下:
ITEM 1: login screen welcome message|ges RESULT: PASSED
ITEM 2.1: File /etc/rc.dt NOT exists|ges RESULT: PASSED
ITEM 2.2: /usr/bin/X11/xhost permission 744|ges RESULT: PASSED
Item 3: Default user password policy and umask|ges RESULT: PASSED
ITEM 4.1 password policy for system users|ges RESULT: PASSED
ITEM 4.2 password policy for application users|ges RESULT: PASSED
ITEM 4.3 password policy for system admin|ges RESULT: PASSED

整理后的结果:
ges|info|ITEM 1:|login screen welcome message|ges RESULT: PASSED   
ges|info|ITEM 2.1:|File /etc/rc.dt NOT exists|ges RESULT: PASSED   
ges|info|ITEM 2.2:|/usr/bin/X11/xhost permission 744|ges RESULT: PASSED    
ges|info|Item 3:|Default user password policy and umask|ges RESULT: PASSED 
ges|info|ITEM 4.1|password policy for system users|ges RESULT: PASSED  
ges|info|ITEM 4.2|password policy for application users|ges RESULT: PASSED  
ges|info|ITEM 4.3|password policy for system admin|ges RESULT: PASSED

中间有个判断passed为info,其他为error

执行文件代码如下:
awk '{$2=$2"|";print $NF ~ /PASSED/ ? "ges|info|"$0 : "ges|error|"$0}'

(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容