perl - Oozie 日志上的模式匹配

标签 perl bash unix hadoop oozie

使用的 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

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

我们将从第二列获取“Status”消息作为<(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

最佳答案

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

perl -pe 's/\B(succeeded|running|suspended|killed|prep)//i and $w=$1 and s/$/    $w/' file

关于perl - Oozie 日志上的模式匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16438423/

相关文章:

perl - 为什么 Perl 会提示 "can' t 修改非左值子例程调用”?

PERL 如何将不在同一行的字符串分组

c - 如何处理socket服务器中select()引起的 "Bad file descriptor"?

linux - Crontab 在半点开始

Perl LWP 手动关闭连接

xml - 使用 Perl 解析 XML 时出现不需要的差异

linux - 从 Bash 中的另一个文本文件中删除文件中包含的单词

linux - 使用 vagrant 和 chef-solo provisioner 安装 django

bash - 获取所有文件夹中所有文件的内容

shell - sed脚本中的空正则表达式