本帖最后由 smss 于 2024-6-21 11:20 编辑
多一行 换行符不一致 明明结尾啥也没有
用Notepad2.exe打开看行尾多出一行CRLF很是奇怪- param([string]$file); #修改前的文件
- $file1 = [io.fileinfo]$file;
- $file2 = [io.path]::Combine($file1.DirectoryName, $file1.BaseName) + '_整理.h';# 新的路径
-
- -replace'(\[[^]]*\])|(?<=[|!]) +','$1' 会把"-delims:| "或"-delims:, "或"-delims:[ "替换为"-delims:|"或"-delims:,"或"-delims:["
-
- #修改以下PowerShell 当其中出现"-delims:| "或"-delims:, "或"-delims:[ " 等只要-delims: 出现则不替换
- #例如
- MSTR * -delims:,&i,&j=<1*>&k 则替换变为 MSTR * -delims:, &i,&j=<1*>&k
- MSTR * -delims:, &i,&j=<1*>&k 则不替换不做任务操作
- MSTR * -delims:%a% &i,&j=<1*>&k 则不替换不做任务操作
- #我尝试
- -replace'(\[[^]]*\])|(?<=[|!])(?<!-delims:) +','$1'
- -replace'delims:(\[|,|\|)','delims:$1 '
- -replace 'delims:(.)(?=\S)(?!:)','delims:$1 ' 但遇MSTR * -delims:%a% 又会被分割成 -delims:% a%
-
- (Get-Content $file2) | ForEach-Object {
- if ($_ -notmatch "-delims:\s*\S") {
- $_ -replace "-delims:", "-delims: "
- } else {
- $_
- }
- } | Set-Content $file2
-
-
-
-
- (Get-Content $file -ReadCount 0)-replace'(\[[^]]*\])|(?<=[|!]) +','$1'-replace'ENVI ','set '-replace'ENVI\^','set^'-replace'envi$','set$'-replace'envi~','set~'-replace'envi\.','set.'-replace'envi<','set<'-replace'envi-ret','set-ret'|Set-Content -encoding Unicode $file2
- #替换后行尾多出一行CRLF
- (Get-Content -Raw -Path $file2 -Encoding Unicode) -replace "`r`n", "`n"| Set-Content -Path $file2 -Encoding Unicode
复制代码 用以下脚本解决- [IO.File]::WriteAllText($file2,([IO.File]::ReadAllText($file, [Text.Encoding]::Unicode) -replace 'ENVI(\^|\$|~|\.|\<|-ret| )','set$1'-replace'\r\n',"`n"),(New-Object System.Text.UnicodeEncoding $fale));
复制代码
|