awk假脱机到CSV文件的特定值(加载到oracle),不带引号| awk | unix [英] awk spool specific values to CSV file (load to oracle) without quotes|awk|unix

查看:118
本文介绍了awk假脱机到CSV文件的特定值(加载到oracle),不带引号| awk | unix的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to extract specific values from a logfile like below :

Table "OWNER123"."MYTABLE":

  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

我想检索的是将输出假脱机到具有以下格式(不带引号)的特定CSV文件:

What i would like to retrieve is to spool the output to a specific CSV file with below format (no quotes) :

MYTABLE,3785568,Sep 01 04:00:26 2017, Sep 01 04:04:45 2017

如何用一个单独的awk命令进行提取?

How is this possible this extraction with one single awk command?

任何帮助将不胜感激:)

Any help would be really much appreciated :)

先谢谢您!

推荐答案

Oneliner

awk -v OFS=, '/^Table/{gsub(/.*\.|[":]/,""); table=$0;next}/Rows successfully loaded/{rows = $1;next}/Run began on/{ sub(/Run began on /,""); start = $0 ;next }/Run ended on/{sub(/Run ended on /,"");print table, rows, start, $0}' logfile

如果要在Solaris/SunOS系统上尝试此操作,请将此脚本开头的awk更改为/usr/xpg4/bin/awk/usr/xpg6/bin/awknawk

If you want to try this on a Solaris/SunOS system, change awk at the start of this script to /usr/xpg4/bin/awk ,/usr/xpg6/bin/awk , or nawk

脚本

Script

[akshay@localhost tmp]$ cat parse.awk
/^Table/{
    gsub(/.*\.|[":]/,"");
    table=$0
    next
}
/Rows successfully loaded/{
        rows = $1
        next
}
/Run began on/{ 
        sub(/Run began on /,""); 
        start = $0 
        next 
}
/Run ended on/{
        sub(/Run ended on /,"");    
        print table, rows, start, $0
        exit
}

执行和输出

Execution & Output

[akshay@localhost tmp]$ awk -v OFS=, -f parse.awk logfile 
MYTABLE,3785568,Fri Sep 01 04:00:26 2017,Fri Sep 01 04:04:45 2017

输入

Input

[akshay@localhost tmp]$ cat logfile 
Table "OWNER123"."MYTABLE":

  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假脱机到CSV文件的特定值(加载到oracle),不带引号| awk | unix的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆