我想运行一段代码,计算一个文本文件中有多少个字符,并将其另存为另一个文本文件,但是我需要输出的只是一个数字。
这是我在PowerShell中运行的代码:
Get-Content [File location] | Measure-Object -Character | Out-File -FilePath [Output Location]
并保存如下输出:
Lines Words Characters Property
----- ----- ---------- --------
1
有什么办法可以只保存号码?
答案 0 :(得分:2)
基本功能:
(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?
答案 1 :(得分:0)
任何东西都是PowerShell中的对象,也适用于Measure-Object的结果。要仅获取属性的值,请使用node
来获取所需的属性Value;
name
在您的示例中:
Select-Object -ExpandProperty <PropertyName>