将文本文件导入 SQL 数据库
我有许多单独的文本文件,我想将它们导入到 SQL 数据库中。数据不是用逗号分隔的,因此排除了使用我通过逗号导入数据的想法。但是,数据跨多行。请参阅下面的示例文本文件。请有人告诉我如何导入特定数据,例如编程值和平均值、班次编号等?
I have a number of separate text files which i would like to import into an SQL database. The data is not comma separted so that rules out using my idea of importing data by comma. However, the data is across a number of rows. See example text file below. Please could anyone advise how i could import specific data such as the programmed and mean values, shift number, etc?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您似乎有一份机器生成的报告。理想的方法是让该机器生成一份不同的报告 - 一份没有“/////”或任何垃圾的报告,只有您想要导入的数据。因此新报告的输出可能如下所示。
但实际上,通常“不可能”获得这样的报告。 (也就是说,机器总是可以做到这一点,但人类通常不愿意。)当这种情况发生时,使用您最喜欢的文本处理语言将报告转换为可用数据。
我喜欢 awk 来处理这类事情。其他人喜欢 Perl。
为了说明这一点,我输入了您报告的副本。 (保存为test.dat。)
然后我编写了这个awk程序。它对报告的布局做出了很多假设。其中一些可能会在真实数据上失败。
输出。 。 。
It looks like you have a machine-generated report. The ideal approach is to have that machine produce a different report--one that has no '/////' or any of that crap, just the data you want to import. So that new report's output might look like this.
In practice, though, it's often not "possible" to get reports like that. (That is, it's always possible for the machine to do it, but often humans are unwilling.) When that happens, use your favorite text-processing language to turn the report into usable data.
I like awk for this kind of stuff. Others like perl.
To illustrate, I keyed in this replica of your report. (Saved as test.dat.)
Then I wrote this awk program. It makes a lot of assumptions about the layout of your report. Some of them will probably fail on real data.
The output . . .
您可以用 C# 编写一个简单的应用程序,以使用正则表达式解析文件的内容,将其转换为一行,并在需要的地方插入分号。
You could write a simple application in C# to parse the contents of the file using regex, turn it into one line, and insert semicolons where required.