在PowerShell中使用回车和换行查找/替换字符串 [英] Find/replace string with carriage return and line feed in PowerShell
本文介绍了在PowerShell中使用回车和换行查找/替换字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法让 PowerShell 找到一个字符串(例如 ~}}|{{E)并替换为回车和换行符 (\r\nE强>)?
Is there a way to have PowerShell find and replace a string (for example ~}}|{{E) with a carriage return and line feed (\r\nE)?
例如:
$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
}
推荐答案
这个怎么样:
$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
}
这篇关于在PowerShell中使用回车和换行查找/替换字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文