我正在尝试编写一个脚本来搜索文件的内容,当它遇到一组ASCII控制字符时,插入一个CR/LF.
我要替换的字符模式是[ETX] [NUL] [STX] [ETX] [SOH]
$filenames = @(Get-Childitem "E:\VendorFiles\*")
$CR = @("[char]3 [char]0 [char]2 [char]3 [char]1")
foreach ($file in $filenames) {$outfile = "$file" + ".txt"
Get-Content $file | Foreach-object {
$_ -replace $CR,"`r`n" `
-replace [char]3,"|" `
-replace [char]1,"{" `
-replace "\\","\\" `
} | Set-Content -encoding "UTF8" $outfile}