如何在Power Shell中逐字读取文件? [英] How to read a file word by word in power shell?
本文介绍了如何在Power Shell中逐字读取文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这种情况下,我得到一个错误.
In this case I am getting an error.
任何人都知道代码中的问题是什么?
Anyone has any idea what's the problem in the code is?
推荐答案
param(
$fileName = "d:\tmp\file.txt",
$name = "Alan"
)
@'
Mohammed 3 4 5 4
Alan 2 1 3 2
Li 3 5 1 3
'@ | Out-File $fileName -Encoding default
$hash = Get-Content $fileName | Where-Object {$_} | ForEach-Object {
$array = $_ -split "\s+"
@{
$array[0] = [Linq.Enumerable]::Average([int[]]($array[1..($array.Count-1)]))
}
}
if ($hash.Keys -contains $name){
return "$name->$($hash.$name)"
}
else {
return "$name=>no $name"
}
这篇关于如何在Power Shell中逐字读取文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文