linux - 优尼克系统 |使用 awk 从日志文件中提取特定值

标签 linux bash unix awk

我正在尝试从如下日志文件中提取特定值:

Table "xxx"."xxxx":

  3785568 Rows successfully loaded.
  0 Rows not loaded due to data errors.
  0 Rows not loaded because all WHEN clauses were failed.
  0 Rows not loaded because all fields were null.

Bind array size not used in direct path.
Column array  rows :    5000
Stream buffer bytes:  256000
Read   buffer bytes: 1048576

Total logical records skipped:          0
Total logical records read:       3785568
Total logical records rejected:         0
Total logical records discarded:        0
Total stream buffers loaded by SQL*Loader main thread:      878
Total stream buffers loaded by SQL*Loader load thread:      796

Run began on Fri Sep 01 04:00:26 2017
Run ended on Fri Sep 01 04:04:45 2017

Elapsed time was:     00:04:19.24
CPU time was:         00:00:08.56

我想要检索的是:

3785568 as number_rows
Sep 01 04:00:26 2017 as start_time
Sep 01 04:04:45 2017 as end_time 

这怎么可能用 awk 提取?

任何帮助将不胜感激:)

非常感谢您的宝贵时间。

最佳答案

awk '/Rows successfully loaded/{
        print $1 " as number_rows"
        next
    }
    /Run began on/{ 
        sub(/Run began on /,""); 
        print $0 " as start_time"
        next 
   }
   /Run ended on/{
        sub(/Run ended on /,"");    
        print $0 " as end_time"
   }' infile

输入

$ cat infile
Table "xxx"."xxxx":

  3785568 Rows successfully loaded.
  0 Rows not loaded due to data errors.
  0 Rows not loaded because all WHEN clauses were failed.
  0 Rows not loaded because all fields were null.

Bind array size not used in direct path.
Column array  rows :    5000
Stream buffer bytes:  256000
Read   buffer bytes: 1048576

Total logical records skipped:          0
Total logical records read:       3785568
Total logical records rejected:         0
Total logical records discarded:        0
Total stream buffers loaded by SQL*Loader main thread:      878
Total stream buffers loaded by SQL*Loader load thread:      796

Run began on Fri Sep 01 04:00:26 2017
Run ended on Fri Sep 01 04:04:45 2017

Elapsed time was:     00:04:19.24
CPU time was:         00:00:08.56

输出

$ awk '/Rows successfully loaded/{
      print $1 " as number_rows"
      next
  }
  /Run began on/{ 
      sub(/Run began on /,""); 
      print $0 " as start_time"
      next 
  }
  /Run ended on/{
      sub(/Run ended on /,""); 
      print $0 " as end_time"
  }' infile

3785568 as number_rows
Fri Sep 01 04:00:26 2017 as start_time
Fri Sep 01 04:04:45 2017 as end_time

关于linux - 优尼克系统 |使用 awk 从日志文件中提取特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46053184/

相关文章:

macos - OS X 挂载本地目录

C:打印共享内存中声明的数组时获取垃圾字符

c++ - 自旋锁与信号量

php - UTF-8贯穿始终

linux - 如何使用linux访问其他系统中的文件

bash - 用 sed 替换由换行符分隔的花括号

linux - git:确定是否有文件不在 repo 协议(protocol)中,但应该添加

Java 匈牙利数字格式和 Linux 文件系统

c - 将 Unix 目录内容打印为普通文本文件

regex - sed 正则表达式及其替代方案在 Solaris 上不起作用