4

有没有办法让 PowerShell 找到并用回车和换行符(\r\nE )替换字符串(例如~}}|{{E)?

例如:

$filenames = @("E:\blergfest.csv")
foreach ($file in $filenames) {
    $outfile = "$file" + ".out"

    Get-Content $file | Foreach-object {
        $_ -replace '\~}}|{{E', '\r\nE' `
            -replace '\|\r\n', '\r\n'
    } | Set-Content $outfile
}
4

2 回答 2

3

要创建包含带有回车和换行的控制字符的字符串,您可以使用双引号并使用反引号字符 `,这是 powershell 转义码。像这样:

"`r`nE"
于 2013-03-07T23:51:57.760 回答
2

这个怎么样:

$filenames = @("E:\blergfest.csv")
foreach ($file in $filenames) {
    $outfile = "$file" + ".out"

    Get-Content $file | Foreach-object {
        $_ -replace '\~}}|{{E', "`r`nE" `
            -replace '\|\r\n', "`r`n"
    } | Set-Content $outfile
}
于 2013-03-07T23:48:32.853 回答