我有以下 CSV 文件,我想将它们合并到一个 CSV 中
01.csv
apples,48,12,7
pear,17,16,2
orange,22,6,1
02.csv
apples,51,8,6
grape,87,42,12
pear,22,3,7
03.csv
apples,11,12,13
grape,81,5,8
pear,11,5,6
04.csv
apples,14,12,8
orange,5,7,9
期望的输出:
apples,48,12,7,51,8,6,11,12,13,14,12,8
grape,,,87,42,12,81,5,8,,,
pear,17,16,2,22,3,7,11,5,6,,,
orange,22,6,1,,,,,,5,7,9
任何人都可以提供有关如何实现这一目标的指导吗?最好使用 Powershell,但如果更容易的话,也可以使用 Perl 等替代品。
谢谢潘蒂克,你的代码的输出接近我想要的:
apples,48,12,7,51,8,6,11,12,13,14,12,8
grape,87,42,12,81,5,8
orange,22,6,1,5,7,9
pear,17,16,2,22,3,7,11,5,6
不幸的是,当 CSV 文件中不存在该条目时,我需要使用“占位符”逗号,例如橙色,22,6,1,5,7,9 而不是橙色,22,6,1,5,7,9
更新:我希望按照文件名的顺序解析这些内容,例如:
$myFiles = @(gci *.csv) | sort Name
foreach ($file in $myFiles){
问候
特德