Shell脚本以查找文件名&每个文件的行数,现在将此记录插入Oracle表 [英] shell script to find filename & line count of each file, now insert this record into Oracle table

查看:73
本文介绍了Shell脚本以查找文件名&每个文件的行数,现在将此记录插入Oracle表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在每个文件行计数的文件夹中找到可用的文件名.然后,我将获得两列数据.

I have to find the filename available in a folder with each file line count. And then, i will have kind of two column data.

现在,我必须将此记录插入到具有两列(col1,col2)的oracle表中.

Now i have to insert this record into a oracle table having two column(col1, col2).

我可以写一个shell脚本来实现这两个功能吗?

Can i write a shell script which will do both.

我在这里发现自己编写了第一部分. 即

I found here itself of writing the first part. i.e

wc -l *| egrep -v " total$" | awk '{print $2 " " $1}' > output.txt

现在,如何将output.txt的数据插入到oracle表中.

Now, how will insert data of output.txt into oracle table.

推荐答案

在版本9i中,Oracle给了我们在11g中使用外部表预处理器列出文件的文章.您的Shell脚本是预处理器功能的理想选择.

In version 9i Oracle gave us external tables. These objects allow us to query data in OS files through SELECT statements. This is pretty cool. Even cooler, in 11.0.1.7 we can associate a shell script with an external table to generate its OS file. Check out Adrian Billington's article on listing files with the external table preprocessor in 11g. Your shell script is an ideal candidate for the preprocessor functionality.

如果出于任何目的现在需要了解目录的内容,则只需从外部表中进行SELECT.如果要永久保存文件名,可以发出INSERT INTO ... SELECT * FROM external_table;.可以使用数据库作业自动运行该语句.

If you need to know the contents of the directory now for whatever purpose you can simply SELECT from the external table. If you want to keep a permanent record of the file names you can issue an INSERT INTO ... SELECT * FROM external_table;. This statement could be run autonomically using a database job.

这篇关于Shell脚本以查找文件名&每个文件的行数,现在将此记录插入Oracle表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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