简体   繁体   English

Powershell import-csv a csv 没有标题〜1200列

[英]Powershell import-csv a csv with no headers ~1200 columns

I have a csv file with no header row (it is actually only 1 row) and about 1200 columns.我有一个 csv 文件,没有 header 行(实际上只有 1 行)和大约 1200 列。 I need to import the csv but if I run it import-csv it treats the first column as headers so I get nothing.我需要导入 csv 但如果我运行它 import-csv 它将第一列视为标题,所以我什么也得不到。 any way to do this without typing 1200 headers in?有什么方法可以在不输入 1200 个标题的情况下做到这一点? Some of the items have commas in the columns.一些项目在列中有逗号。

You can fake the headers.你可以伪造标题。 This does mean you need to reference each property to access the value.这确实意味着您需要引用每个属性来访问该值。

$headers = 1..1200
$data = Import-Csv file.csv -Header $headers

Each data row (non-header row) is read into an array ( $data ), which starts its index at 0. This would mean data row 1 column 1 is accessed by $data[0].1 .每个数据行(非标题行)都被读入一个数组( $data ),它的索引从 0 开始。这意味着数据行 1 列 1 由$data[0].1访问。 Data row 2 and column 4 would be $data[0].4 .数据第 2 行和第 4 列将是$data[0].4 If there were a data row 5 and column 900, it would be $data[4].900 .如果有数据第 5 行和第 900 列,它将是$data[4].900

If you only want to see the CSV data without the headers, you can do the following:如果您只想查看没有标题的 CSV 数据,可以执行以下操作:

$data | ConvertTo-Csv -NoType | Select -Skip 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM