Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.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 使用post.context替换命令以添加新行_Powershell_Replace_Line Breaks - Fatal编程技术网

Powershell 使用post.context替换命令以添加新行

Powershell 使用post.context替换命令以添加新行,powershell,replace,line-breaks,Powershell,Replace,Line Breaks,试图在此处添加换行符,但无效。还尝试使用`r,但没有成功 我的代码: $extract = @() Select-String -Path $outfile -Pattern "text" -Context 0,12 | ForEach-Object { $extract += $_.Line | foreach {$_.Replace("text", "DD/MM")} $extract += $_.Context.PostContext | forea

试图在此处添加换行符,但无效。还尝试使用
`r
,但没有成功

我的代码:

$extract = @()
Select-String -Path $outfile -Pattern "text" -Context 0,12 |
    ForEach-Object {
        $extract += $_.Line | foreach {$_.Replace("text", "DD/MM")}
        $extract += $_.Context.PostContext | foreach {$_.Replace(',', "`n")}
    }
$extract | Out-File $outfile1
我的意见:

DD/MM 27,28 14 21 1 15 7 12 2,15 25 日/月 27,28 14 21 1. 15 7. 12 2,15 25 我想做的是为27,28和2,15添加一个换行符,这样它可以在单独的一行中读取每个数字:

27 28 2 15 27 28 2. 15
知道为什么这里的替换不起作用吗?

请提供示例输入。输入$outfile与输出相同,我可以用任何其他字符替换逗号,或者什么都不替换,但是当我尝试用新行替换逗号时,它不起作用。DD/MM 27,28 14 21 1 15 7 12 2,15 25您发布的代码已经可以处理了。我同意,但遗憾的是:它没有:(我正在使用powershell 4.0,不知道这个版本是否有什么东西,但无论如何,会继续尝试。无论如何,我感谢您的帮助。找到了!!!!:)我忘了添加“r”,所以现在它可以按照我的意愿工作了……:D