我想运行一段计算文本文件中有多少个字符的代码,并将其另存为另一个文本文件,但我需要的输出只是一个数字。
这是我在PowerShell中运行的代码:
Get-Content [File location] | Measure-Object -Character | Out-File -FilePath [Output Location]
它像这样保存输出:
Lines Words Characters Property
----- ----- ---------- --------
1 有没有办法只保存号码?
发布于 2019-08-04 22:54:20
基本powershell:
(Get-Content file | Measure-Object -Character).characters或
Get-Content file | Measure-Object -Character | select -expand characters相关:How to get an object's property's value by property name?
发布于 2019-08-04 23:11:55
在PowerShell中,任何东西都是对象,这也是Measure-Object的结果。要只获取属性的值,请使用Select-Object -ExpandProperty <PropertyName>获取所需的属性值;
PS> Get-ChildItem | Measure-Object | Select-Object -ExpandProperty Count
PS> 3在您的示例中:
PS> Get-Content [File location] |
Measure-Object |
Select-Object -ExpandProperty Count |
Out-File -FilePath [Output Location]https://stackoverflow.com/questions/57347558
复制相似问题