在此处输入代码正在寻找一种解决方案,以压缩我收到的日志输出。我只需要CLEARED_TIME之前的列信息,而忽略ALARM_GROUP之后的输出。列的宽度有时会膨胀和收缩。另外,来自CLEARD_TIME的字段编号不是静态的,可能输出明确的日期,或者是破折号。
找到解决方案:
TOVYILAABBULTE0491808 RTRV-ALM-LOG | gawk '/LOG_NO/,/COUNT/ {if ($1 == "LOG_NO") p = index($0,"ALARM_GROUP")-1} {if ($1 == "LOG_NO") print substr($0,1,p)} {if ($2 == "RRH" && $3 == "COMMUNICATION_FAIL" ) print substr($0,1,p)}'
Current Output :
LOG_NO UNIT_TYPE ALARM_TYPE LOCATION RAISED_TIME CLEARED_TIME ALARM_GROUP PROBABLE_CAUSE SEVERITY ALARM_CODE
2 RRH COMMUNICATION_FAIL RRH[0_4_0]-RRH[0_4_0] 2019-03-19 06:06:49 2019-03-19 06:06:58 EQUIPMENT_ALARM LINK_FAILURE major 3149381
3 RRH COMMUNICATION_FAIL RRH[0_4_0]-RRH[0_4_0] 2019-03-19 06:38:29 2019-03-19 06:38:38 EQUIPMENT_ALARM LINK_FAILURE major 3149381
8 RRH COMMUNICATION_FAIL RRH[0_4_0]-RRH[0_4_0] 2019-03-19 07:47:59 2019-03-19 07:48:38 EQUIPMENT_ALARM LINK_FAILURE major 3149381
9 RRH COMMUNICATION_FAIL RRH[0_8_0]-RRH[0_8_0] 2019-03-19 07:54:39 - EQUIPMENT_ALARM LINK_FAILURE major 3149381
10 RRH COMMUNICATION_FAIL RRH[0_4_0]-RRH[0_4_0] 2019-03-19 09:15:59 2019-03-19 09:16:28 EQUIPMENT_ALARM LINK_FAILURE major 3149381
11 RRH COMMUNICATION_FAIL RRH[0_4_0]-RRH[0_4_0] 2019-03-19 14:13:49 2019-03-19 14:14:18 EQUIPMENT_ALARM LINK_FAILURE major 3149381
12 RRH COMMUNICATION_FAIL RRH[0_4_0]-RRH[0_4_0] 2019-03-19 15:10:09 - EQUIPMENT_ALARM LINK_FAILURE major 3149381
13 RRH COMMUNICATION_FAIL RRH[0_4_0]-RRH[0_4_0] 2019-03-19 15:48:19 2019-03-19 15:48:48 EQUIPMENT_ALARM LINK_FAILURE major 3149381
14 RRH COMMUNICATION_FAIL RRH[0_4_0]-RRH[0_4_0] 2019-03-19 17:47:59 2019-03-19 17:48:08 EQUIPMENT_ALARM LINK_FAILURE major 3149381
15 RRH COMMUNICATION_FAIL RRH[0_4_0]-RRH[0_4_0] 2019-03-19 18:01:29 2019-03-19 18:03:18 EQUIPMENT_ALARM LINK_FAILURE major 3149381
Desired Output :
LOG_NO UNIT_TYPE ALARM_TYPE LOCATION RAISED_TIME CLEARED_TIME
2 RRH COMMUNICATION_FAIL RRH[0_4_0]-RRH[0_4_0] 2019-03-19 06:06:49 2019-03-19 06:06:58
3 RRH COMMUNICATION_FAIL RRH[0_4_0]-RRH[0_4_0] 2019-03-19 06:38:29 2019-03-19 06:38:38
8 RRH COMMUNICATION_FAIL RRH[0_4_0]-RRH[0_4_0] 2019-03-19 07:47:59 2019-03-19 07:48:38
9 RRH COMMUNICATION_FAIL RRH[0_8_0]-RRH[0_8_0] 2019-03-19 07:54:39 -
10 RRH COMMUNICATION_FAIL RRH[0_4_0]-RRH[0_4_0] 2019-03-19 09:15:59 2019-03-19 09:16:28
11 RRH COMMUNICATION_FAIL RRH[0_4_0]-RRH[0_4_0] 2019-03-19 14:13:49 2019-03-19 14:14:18
12 RRH COMMUNICATION_FAIL RRH[0_10_0]-RRH[0_10_0] 2019-03-19 15:10:09 -
13 RRH COMMUNICATION_FAIL RRH[0_4_0]-RRH[0_4_0] 2019-03-19 15:48:19 2019-03-19 15:48:48
14 RRH COMMUNICATION_FAIL RRH[0_4_0]-RRH[0_4_0] 2019-03-19 17:47:59 2019-03-19 17:48:08
15 RRH COMMUNICATION_FAIL RRH[0_4_0]-RRH[0_4_0] 2019-03-19 18:01:29 2019-03-19 18:03:18
答案 0 :(得分:0)
查看这些数据,最简单的解决方案是将print $0
替换为print substr($0,1,126)
,并根据需要调整这些参数,以防它们不正确。