Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试使用powershell分析输出文件_Powershell - Fatal编程技术网

尝试使用powershell分析输出文件

尝试使用powershell分析输出文件,powershell,Powershell,我有一个监控特定流程的脚本,我有一个输出该流程的工作脚本 0 0 0 我正在使用此脚本尝试在使用此脚本的第一个“0”之后剪切所有内容 Get-Content –path c:\batchjobs\location\test.txt | Trim(Char[8,60]) > c:\batchjobs\location\test1.txt powershell ise不断出错,以下是输出: PS C:\batchjobs\location> C:\batchjobs\loca

我有一个监控特定流程的脚本,我有一个输出该流程的工作脚本

0   0   0
我正在使用此脚本尝试在使用此脚本的第一个“0”之后剪切所有内容

Get-Content –path c:\batchjobs\location\test.txt | Trim(Char[8,60]) > c:\batchjobs\location\test1.txt
powershell ise不断出错,以下是输出:

PS C:\batchjobs\location> C:\batchjobs\location\TestTrim.ps1
The term 'Trim' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, 
or if a path was included, verify that the path is correct and try again.
At C:\batchjobs\location\TestTrim.ps1:2 char:58
+ Get-Content –path c:\batchjobs\location\test.txt | Trim <<<< (Char[8,60]) > c:\batchjobs\location\test1.txt
    + CategoryInfo          : ObjectNotFound: (Trim:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
PS C:\batchjobs\location>C:\batchjobs\location\TestTrim.ps1
术语“Trim”不能识别为cmdlet、函数、脚本文件或可操作程序的名称。检查名字的拼写,
或者,如果包含路径,请验证路径是否正确,然后重试。
位于C:\batchjobs\location\TestTrim.ps1:2 char:58

+获取内容–路径c:\batchjobs\location\test.txt | Trim方法,如
Trim
SubString
需要对对象进行操作,但您没有告诉脚本您指的是哪个对象。在上下文中,您将希望为结果对象指示
$\uu
。此外,Get Content将返回文件的所有行,并使用
对每行进行迭代,即a.k.a
%

Get-Content -path c:\batchjobs\location\test.txt | % { $_.Substring(0,7).Trim(); } > c:\batchjobs\location\test1.txt

Trim
SubString
这样的方法需要对一个对象进行操作,而不是告诉脚本您指的是哪个对象。在上下文中,您将希望为结果对象指示
$\uu
。此外,Get Content将返回文件的所有行,并使用
对每行进行迭代,即a.k.a
%

Get-Content -path c:\batchjobs\location\test.txt | % { $_.Substring(0,7).Trim(); } > c:\batchjobs\location\test1.txt

Trim
SubString
这样的方法需要对一个对象进行操作,而不是告诉脚本您指的是哪个对象。在上下文中,您将希望为结果对象指示
$\uu
。此外,Get Content将返回文件的所有行,并使用
对每行进行迭代,即a.k.a
%

Get-Content -path c:\batchjobs\location\test.txt | % { $_.Substring(0,7).Trim(); } > c:\batchjobs\location\test1.txt

Trim
SubString
这样的方法需要对一个对象进行操作,而不是告诉脚本您指的是哪个对象。在上下文中,您将希望为结果对象指示
$\uu
。此外,Get Content将返回文件的所有行,并使用
对每行进行迭代,即a.k.a
%

Get-Content -path c:\batchjobs\location\test.txt | % { $_.Substring(0,7).Trim(); } > c:\batchjobs\location\test1.txt

假设您的文件的大小使您不会使用get content开始出现内存不足错误,那么这种方法就可以了。如果您想要一个大文件的前8个字符(可能是1GB大小?),那么以下方法可能更灵活一些:

$stream = [System.IO.StreamReader]"C:\Users\Ryan\Desktop\test.csv"
$i=0

#read characters until we get to 8 or end of the stream. won't load the while file into memory
$output = while(($i -lt 8) -and (!$stream.EndOfStream)){ [char]$stream.Read(); $i++ }
$stream.close()

假设您的文件的大小使您不会使用get content开始出现内存不足错误,那么这种方法就可以了。如果您想要一个大文件的前8个字符(可能是1GB大小?),那么以下方法可能更灵活一些:

$stream = [System.IO.StreamReader]"C:\Users\Ryan\Desktop\test.csv"
$i=0

#read characters until we get to 8 or end of the stream. won't load the while file into memory
$output = while(($i -lt 8) -and (!$stream.EndOfStream)){ [char]$stream.Read(); $i++ }
$stream.close()

假设您的文件的大小使您不会使用get content开始出现内存不足错误,那么这种方法就可以了。如果您想要一个大文件的前8个字符(可能是1GB大小?),那么以下方法可能更灵活一些:

$stream = [System.IO.StreamReader]"C:\Users\Ryan\Desktop\test.csv"
$i=0

#read characters until we get to 8 or end of the stream. won't load the while file into memory
$output = while(($i -lt 8) -and (!$stream.EndOfStream)){ [char]$stream.Read(); $i++ }
$stream.close()

假设您的文件的大小使您不会使用get content开始出现内存不足错误,那么这种方法就可以了。如果您想要一个大文件的前8个字符(可能是1GB大小?),那么以下方法可能更灵活一些:

$stream = [System.IO.StreamReader]"C:\Users\Ryan\Desktop\test.csv"
$i=0

#read characters until we get to 8 or end of the stream. won't load the while file into memory
$output = while(($i -lt 8) -and (!$stream.EndOfStream)){ [char]$stream.Read(); $i++ }
$stream.close()

我不确定Char[8,60]是什么意思,所以我只放了子字符串(8,1),它只输出行的第8个字符。如果您有其他意图,也许您可以根据自己的喜好修改此内容,或者让我知道您的意图。哦,很抱歉,字符[8,60]是我试图删除上一行第8个字符中的所有内容,我只需要前7个字符,这是否有帮助?请确保,只使用子字符串(0,7)-我将更新我的示例。希望有帮助。谢谢你,Matthew,非常感谢我不确定你所说的字符[8,60]是什么意思,所以我只放了子字符串(8,1),它将只输出行的第8个字符。如果您有其他意图,也许您可以根据自己的喜好修改此内容,或者让我知道您的意图。哦,很抱歉,字符[8,60]是我试图删除上一行第8个字符中的所有内容,我只需要前7个字符,这是否有帮助?请确保,只使用子字符串(0,7)-我将更新我的示例。希望有帮助。谢谢你,Matthew,非常感谢我不确定你所说的字符[8,60]是什么意思,所以我只放了子字符串(8,1),它将只输出行的第8个字符。如果您有其他意图,也许您可以根据自己的喜好修改此内容,或者让我知道您的意图。哦,很抱歉,字符[8,60]是我试图删除上一行第8个字符中的所有内容,我只需要前7个字符,这是否有帮助?请确保,只使用子字符串(0,7)-我将更新我的示例。希望有帮助。谢谢你,Matthew,非常感谢我不确定你所说的字符[8,60]是什么意思,所以我只放了子字符串(8,1),它将只输出行的第8个字符。如果您有其他意图,也许您可以根据自己的喜好修改此内容,或者让我知道您的意图。哦,很抱歉,字符[8,60]是我试图删除上一行第8个字符中的所有内容,我只需要前7个字符,这是否有帮助?请确保,只使用子字符串(0,7)-我将更新我的示例。希望有帮助。谢谢你,马修,非常感谢