使用linuxjishu/13830.html target=_blank class=infotextkey>awk整理日志格式的单行命令,有需要的朋友不妨看看。
有如下的文本:
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}'