我正在尝试从如下日志文件中提取特定值:
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/