Powershell代码:
(Get-Content hist3.txt) | ForEach-Object { $_.split(" ",2)[0]} | ForEach-Object { $rgbArray = @($_)} | for( $i = 0; $i -le $rgbArray.length - 1; $i++ ) {$rgbArray[$i]}
错误信息:
一行:1字符:114
- CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
- FullyQualifiedErrorId : MissingEndParenthesisInExpression
第三组:
2 1388581
3 1449812
4 63829
5 10477
6 5878
7 6703
8 105349
9 8639
10 7270
(Get-Content hist3.txt)
ForEach-Object { $_.split(" ",2)[0]}
ForEach-Object { $rgbArray = @($_)}
for( $i = 0; $i -le $rgbArray.length - 1; $i++ ) {$rgbArray[$i]}
我的上述代码似乎遗漏了一个括号。或者它没有识别出管道后面的$rgbArray?
你能告诉我我遗漏或需要阅读哪些信息吗?我该怎么做呢?
最终目标是将元素实际加载到数组中,然后将几个元素与同一数组中的其他元素进行比较。因此,我将同时访问同一个数组的多个部分。
非常新的powershell,所以感谢您的帮助。
发布于 2017-01-15 04:14:32
您不能将任何东西输送到for
中。约为描述它是语言命令,而不是cmdlet。
很难猜出你的最终目标。首先,按顺序尝试下一个代码片段,看看会发生什么:
Get-Content 'hist3.txt'
然后
Get-Content 'hist3.txt' | ForEach-Object { $_.split(" ",2)[0]}
然后
Get-Content 'hist3.txt' | ForEach-Object { $_.split(" ",2)[0]} |
ForEach-Object {
$rgbArray = @($_)
for( $i = 0; $i -le $rgbArray.length - 1; $i++ ) {$rgbArray[$i]}
}
后者与下一个班轮相同:
(Get-Content 'D:\PShell\Downloaded\hist3.txt.txt' ) | ForEach-Object { $_.split(" ",2)[0]} | ForEach-Object { $rgbArray = @($_); for( $i = 0; $i -le $rgbArray.length - 1; $i++ ) {$rgbArray[$i]}}
发布于 2017-01-15 10:35:34
#you can do simply that:
Import-Csv 'hist3.txt' -Delimiter ' ' -Header Col1, Col2 | select Col1
#or this
Get-Content 'hist3.txt' | %{ ($_ -split ' ')[0]}
https://stackoverflow.com/questions/41657595
复制相似问题