How To Access Specific Rows in an Import-Csv Array?

三世轮回 提交于 2019-12-02 10:44:12

Import-Csv imports the file as an array of objects, so you could do something like this (using the range operator):

$csv = Import-CSv $CSVPath -Delimiter '|'
$SOAData = $csv[20000..29999] | ForEach-Object { ... }

An alternative would be to use Select-Object:

$offset = 20000
$count  = 10000
$csv = Import-Csv $CSVPath -Delimiter '|'
$SODAData = $csv |
            Select-Object -Skip $offset -First $count |
            ForEach-Object { ... }

If you want to avoid reading the entire file into memory you can change the above to a single pipeline:

$offset = 20000
$count  = 10000
$SODAData = Import-Csv $CSVPath -Delimiter '|' |
            Select-Object -Skip $offset -First $count |
            ForEach-Object { ... }

Beware, though, that with this approach you need to read the file multiple times for processing multiple chunks of data.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!