【问题标题】:grep command to extract time in "HR:MIN MST" format from the log filegrep 命令以“HR:MIN MST”格式从日志文件中提取时间
【发布时间】:2018-10-28 01:25:39
【问题描述】:

这是我从程序创建的日志文件格式示例。

示例日志文件

Job execution started 2018-05-16 05:54:08 MST
Starting  job for '2018-05-16' 
Starting  job for '2018-05-16' 
Control table  count is : '33768' 
Processing batch_id: '11548
11568
11598
11611
11637
11662
11688
Completed  job for '2018-05-16' 
Job execution completed 2018-05-16 06:04:59 MST

我只想从日志文件中提取开始时间和结束时间。谁能帮我确定如何实现这一目标?

【问题讨论】:

    标签: awk grep extract text-processing


    【解决方案1】:

    你可以使用awk 喜欢:

    awk -F'[ :]' '/Job execution (started|completed)/{ print $5 ":" $6, $8}' infile
    

    这会将字段分隔符设置为 冒号或空格,并仅从与给定模式 /.../ 匹配的行中打印字段 5、6 和 7。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-29
      • 2012-11-05
      • 2019-03-08
      • 1970-01-01
      • 2021-12-13
      相关资源
      最近更新 更多