从linux中的文本文件中提取值

时间:2014-03-18 02:42:53

标签: linux

我有一个从sqlldr日志文件生成的日志文件,我想知道我是否可以编写一个shell来使用Linux从下面的日志中提取以下值。感谢

表名:TEST
Row_load:100
Row_fail:10
Date_run:2014年2月7日

Table TEST:
100 Rows successfully loaded.
10 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:         14486
Total logical records rejected:         0
Total logical records discarded:        0
Total stream buffers loaded by SQL*Loader main thread:        3
Total stream buffers loaded by SQL*Loader load thread:        0

Run began on Fri Feb 07 12:21:24 2014
Run ended on Fri Feb 07 12:21:31 2014

Elapsed time was:     00:00:06.88
CPU time was:         00:00:00.11

1 个答案:

答案 0 :(得分:0)

如果日志文件的结构始终相同,那么您可以使用awk执行以下操作:

awk '
NR==1 { sub(/:/,x); print "Table_name: "$NF}
NR==2 { print "Row_load: " $1}
NR==3 { print "Row_fail: " $1}
/Run ended/ { print "Date_run: "$5 FS $6","$8}' file

输出

$ awk '
NR==1 { sub(/:/,x); print "Table_name: "$NF}
NR==2 { print "Row_load: " $1}
NR==3 { print "Row_fail: " $1}
/Run ended/ { print "Date_run: "$5 FS $6","$8}' file
Table_name: TEST
Row_load: 100
Row_fail: 10
Date_run: Feb 07,2014