繁体   English   中英

如何将get-content输出到Powershell中的数组?

[英]How to output get-content to array in powershell?

我有以下代码:

get-content C:\file.txt | Foreach{($_ | Select-String "$" -all).Matches | measure | select count} 

我想在每行文件中找到$的数目,该数目可以成功运行,我得到了每行每个字符数的表格计数。 但是,我想将每个值作为一个值输出到数组,并对计数执行算术运算。 就目前而言,我尝试过的一切都给了我一个多维数组,而不是整数数组。 例如我试过

$counts = @(get-content C:\ampersand.txt | Foreach{($_ | Select-String "&" -all).Matches | measure | select count} )

但这只是吐出一个多维数组,我无法对它执行算术运算

我认为这只是PowerShell陷阱的其中之一。 $Counts不是整数数组,而是具有count属性的对象数组。

get-content C:\file.txt | Foreach{($_ | Select-String "$" -all).Matches | measure | select-object -ExpandProperty count}

暂无
暂无

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

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