1

使用 Oozie 命令

oozie jobs -oozie http://localhost:11000/oozie -localtime | grep "2013-05-08" > Input.txt

Oozie 日志 (Input.txt)

61-oozie     DProSUCCEEDED chronicles      users     2013-05-08 04:47        2013-05-08 04:53
61-oozie     DPRUNNING chronicles      users     2013-05-08 04:47        
61-oozie     DProcessSuspended chronicles      users     2013-05-08 04:42        2013-05-08 04:48
61-oozie     DKILLED chronicles      users     2013-05-08 04:07        2013-05-08 04:09

我想要一个额外的列作为“Status”,它将状态消息存储为“SUCCESS/RUNNING/KILLED/SUSPENDED/Prep”。

我们将从第二列获取“状态”消息,如<(processname)><(Status)>。

我无法从上面的文本中猜出分隔符。因此我们可以利用 AWK/cut/substring 概念。

Status messages are static . Job names are dynamic.

将有4 条状态消息

  • 成功
  • 跑步
  • 准备
  • 杀死
  • 暂停

期望的输出

61-oozie     DPro chronicles      users     2013-05-08 04:47        2013-05-08 04:53    SUCCEEDED
61-oozie     DP chronicles      users     2013-05-08 04:47          -       RUNNING
61-oozie     DProcess chronicles      users     2013-05-08 04:42        2013-05-08 04:48    Suspended
61-oozie    D chronicles      users     2013-05-08 04:07        2013-05-08 04:09    KILLED
4

2 回答 2

1

提取所需状态并将其放在行尾,

perl -pe 's/\B(succeeded|running|suspended|killed|prep)//i and $w=$1 and s/$/    $w/' file
于 2013-05-08T11:19:30.830 回答
0
sed 's/(\w+)(SUCCEEDED|RUNNING|Prep|KILLED|SUSPENDED)(\s+.+)$/\1\3 \2/g'

即pre-status, status, post-status -> pre-status, post-status, status

由于您似乎在输入和所需输出的状态之间存在差异,例如“ProcessSuspended”输入和“SUSPENDED”输出,那么您可能还想交换这些:

sed 's/(\w+)(SUCCEEDED|RUNNING|Prep|KILLED|SUSPENDED)(\s+.+)$/\1\3 \2/g' | sed 's/ProcessSuspended$/SUSPENDED/g'

或者使用 Perl 并进行查找。

于 2013-05-08T10:39:40.163 回答