当文件没有标题行时,如何使用 Import-CSV 导入制表符分隔的文本文件? [英] How can I import a tab delimited text file with Import-CSV when the file has no header row?
本文介绍了当文件没有标题行时,如何使用 Import-CSV 导入制表符分隔的文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个巨大的文本文件(大约 500 MB),以制表符分隔.它不包含标题.所以它看起来像:
I have a huge text file (around 500 MB) that is tab delimited. It doesn't contain headers. So it looks like:
20140711 IBM 29.9068 tom.smith@ibm.com this is interesting
20140712 HP 2.3000 tom.smith@ibm.com this is interesting
20140713 GOOGLE 44.9033 tom.smith@ibm.com this is interesting
20140714 HTC 739.70 tom.smith@ibm.com this is interesting
20140715 SAMSUNG 8.442 tom.smith@ibm.com this is interesting
20140716 MICROSOFT 67.104 tom.smith@ibm.com this is interesting
20140717 DELL 5.0823 tom.smith@ibm.com this is interesting
...
...
...
我需要使用 Powershell 将文本作为表加载到 SQL Server 数据库中.由于文本文件中没有标题,Import-Csv"cmdlet 会错误地输出内容.我认为它总是将第一行视为标题.
I need to use Powershell to load the text into the SQL Server database as a table. As there is no headers in the text file, the "Import-Csv" cmdlet output the content incorrectly. I think it always treats the first line as headers.
Import-Csv"如何输出文本文件中的任何内容而忘记标题配置?
How can "Import-Csv" output whatever in the text file and forget about header config?
谢谢.
推荐答案
你可以试试这个:
$data = Import-Csv C:\temp\F.csv -Header "date","company","value","mail","description" -Delimiter "`t"
这篇关于当文件没有标题行时,如何使用 Import-CSV 导入制表符分隔的文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文