小编Jer*_*ton的帖子

Powershell:查找/替换ASCII控制字符的模式

我正在尝试编写一个脚本来搜索文件的内容,当它遇到一组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}

powershell scripting ascii control-characters

5
推荐指数
1
解决办法
8540
查看次数

标签 统计

ascii ×1

control-characters ×1

powershell ×1

scripting ×1