我有一个需要输出诊断结果的任务 - 是否通过“P”,失败“F”,停止“H”。至于在示例输入文件中找不到的cps_ck
,它会给我“X”,意思是“未执行”。
S----------------------------------------------S
S hss_ck | meter_ck | fan_ck | ovi_ck | cps_ck S
S----------------------------------------------S
S F | F | H | P | X S
S----------------------------------------------S
这是日志文件的示例内容,我将提取“P”,“F”和“H”。它始终处于“dir to my diags”“result”“date”“time”的模式中。对于此日志文件,最后执行的诊断结束。另一个挑战是可能存在两个或更多“hss_ck.vti”结果,如下面的示例所示。我想得的只是最新的结果,样本数据中的“F”。
/home/bigdir/subdir/os/i686_linux_2.6.9/diags/hss_ck.vti P 06-24-2015 21:00:12
/home/bigdir/subdir/os/i686_linux_2.6.9/diags/fan_ck.eva H 06-24-2015 21:00:35
/home/bigdir/subdir/os/i686_linux_2.6.9/diags/meter_ck.eva F 06-24-2015 21:01:16
/home/bigdir/subdir/os/i686_linux_2.6.9/diags/ovi_ck.eva P 06-24-2015 21:02:01
/HOME/smalldir/rrim/OVICAL/ovi_cal.eva P 06-24-2015 21:32:10
/home/bigdir/subdir/os/i686_linux_2.6.9/diags/hss_ck.vti F 06-25-2015 01:00:12
我心中的想法是这样的:
/tmp/MyArrayIsHere
。非常感谢任何帮助。
答案 0 :(得分:1)
awk 'BEGIN {
o[1] = "hss_ck"; o[2] = "meter_ck"; o[3] = "fan_ck"; o[4] = "ovi_ck"; o[5] = "cps_ck"
for (i = 1; i <= 5; i++) a[o[i]] = "X"
}
{ x = $1; sub(/.*\//, "", x); sub(/\.[a-z]{3}$/, "", x); if (x in a) a[x] = $2; }
END {
print "S----------------------------------------------S"
print "S hss_ck | meter_ck | fan_ck | ovi_ck | cps_ck S"
print "S----------------------------------------------S"
prefix = "S"
for (i = 1; i <= 5; i++)
{
len = length(o[i]) / 2
printf("%s%*s%s%*s", prefix, len, " ", a[o[i]], len+1, " ")
prefix = "|"
}
printf "S\n"
print "S----------------------------------------------S"
}' data
概要
o
),然后重新打印。a
中的状态初始化为X
(未执行)。$1
中提取代码;如果代码是有趣的代码之一,请将$2
的值保存在a
中。最新值将覆盖之前的值。o
中的数据生成,而不是硬编码。/home/bigdir/subdir/os/i686_linux_2.6.9/diags/hss_ck.vti P 06-24-2015 21:00:12
/home/bigdir/subdir/os/i686_linux_2.6.9/diags/fan_ck.eva H 06-24-2015 21:00:35
/home/bigdir/subdir/os/i686_linux_2.6.9/diags/meter_ck.eva F 06-24-2015 21:01:16
/home/bigdir/subdir/os/i686_linux_2.6.9/diags/ovi_ck.eva P 06-24-2015 21:02:01
/HOME/smalldir/rrim/OVICAL/ovi_cal.eva P 06-24-2015 21:32:10
/home/bigdir/subdir/os/i686_linux_2.6.9/diags/hss_ck.vti F 06-25-2015 01:00:12
S----------------------------------------------S
S hss_ck | meter_ck | fan_ck | ovi_ck | cps_ck S
S----------------------------------------------S
S F | F | H | P | X S
S----------------------------------------------S