我正在处理一个大文本文件,我的意思是超过 100 MB 大,我需要循环遍历特定数量的行,这是一种子集,所以我正在尝试使用这个,
$info = Get-Content -Path $TextFile | Select-Object -Index $from,$to
foreach ($line in $info)
{
,,,
但这不起作用。就像它只获取子集中的第一行一样。
我没有找到有关 Index 属性的文档,那么这是否可能,或者考虑到文件大小,我应该尝试使用不同的方法?
PS> help select -param index
-Index <Int32[]>
Selects objects from an array based on their index values. Enter the indexes in a comma-separated list.
Indexes in an array begin with 0, where 0 represents the first value and (n-1) represents the last value.
Required? false
Position? named
Default value None
Accept pipeline input? false
Accept wildcard characters? false
根据上面的内容,“8,13”只会给你两行。您可以做的一件事是传递一个数字数组,您可以使用范围运算符:
Get-Content -Path $TextFile | Select-Object -Index (8..13) | Foreach-Object {...}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)