使用 PowerShell 从 CSV 进行对象关系映射? [英] Object Relational Mapping from CSV with PowerShell?
问题描述
"如何从 PowerShell
遍历 CSV
数据?"可能是一个替代的问题标题.
"How to iterate through CSV
data from PowerShell
?" would perhaps be an alternate question title.
这个输出很好:
PS /home/nicholas>
PS /home/nicholas> $flat
Date Region New_Tests Total_Tests Positivity Turn_Around
---- ------ --------- ----------- ---------- -----------
2020-01-23 BC 2 2 0 32
2020-01-23 Fraser 0 0 0 0
2020-01-23 Interior 0 0 0 0
2020-01-23 Northern 0 0 0 0
2020-01-23 Unknown 0 0 0 0
2020-01-23 Vancouver Coastal 2 2 0 32
2020-01-23 Vancouver Island 0 0 0 0
..
但我更感兴趣的是,例如,像这样基本的SQL
:
but I'd be more interested in, for example, something like this basic SQL
:
SELECT * FROM $flat limit 3
或使用 WHERE
子句.也许甚至只是返回行/记录 n
?最好表示为:
or using WHERE
clauses. Perhaps even just returning row/record n
? Preferably represented as:
Date : 2020-11-19
Region : Vancouver Island
New_Tests : 1682
Total_Tests : 118623
Positivity : 1.4
Turn_Around : 12.7
我认为,也许,字段
或properties
属于通用Object
.
Which I take as, perhaps, the fields
or properties
belonging to a generic Object
.
如何在 Linux
上的 Powershell
中将 CSV
中的一行映射到 Object
?
How do I map a row from CSV
to an Object
in Powershell
on Linux
?
推荐答案
你测试 Import-Csv
CmdLet :
Do you test Import-Csv
CmdLet :
Import-Csv 'your_file.csv' -Delimiter ';'
在你的情况 ConvertFrom-Csv
CmdLet :
in your case ConvertFrom-Csv
CmdLet :
$labs_csv | ConvertFrom-Csv -Delimiter ';'
这篇关于使用 PowerShell 从 CSV 进行对象关系映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!