Board logo

标题: [问题求助] [已解决]求合并一句PowerShell脚本 [打印本页]

作者: smss    时间: 2019-6-22 22:45     标题: [已解决]求合并一句PowerShell脚本

本帖最后由 smss 于 2019-6-24 16:25 编辑
  1. $str = [IO.File]::ReadAllText('manifest.xml', [Text.Encoding]::UTF8);
  2. $str = $str -replace '(?m)^\s+|\s*(?:\n|$)' -replace '<!--(?:(?!-->).)*-->'  -replace '(?<!<\S+)\s+';
  3. $str = [regex]::Replace($str, '(?<=<[^<>\s]+)\s+[^<>]+"(?=\s*/?>)', {param($m); [Collections.ArrayList]$a=$m.Value -split '(?<=="[^"]*")';$a.Reverse();$a -join ''});
  4. [IO.File]::WriteAllText('1.xml', $str, [Text.Encoding]::UTF8);
复制代码
  1. Get-Date -Format "<!--smss于yyyy年M月d日 HH:mm:ss制作-->" |  out-file -filepath 1.xml -appen
复制代码
需要把最后一句改为
放在生成文本第二行
目前是追加到文本尾
而不是文本的第二行
最好注释说明下谢谢
作者: WHY    时间: 2019-6-24 15:43

第一个脚本把回车换行符全部删掉了,生成的 1.xml 只有一行。
第二个脚本生成了一个注释语句,追加到第二行,也是最后一行,有什么问题吗?
第二个脚本 $file2 指的什么? 你的样本在哪里?
作者: smss    时间: 2019-6-24 15:47

本帖最后由 smss 于 2019-6-24 16:27 编辑

回复 2# WHY

对不起 我改过一次 让你发现了
下面这句加至$file2 也就是生成的1.xml的第二句 直接运行会对UTF8编码的xml生成乱码 呜呜呜
  1. Get-Date -Format "<!--smss于yyyy年M月d日 HH:mm:ss制作-->" |  out-file -filepath $file2 -appen
复制代码

作者: WHY    时间: 2019-6-24 16:08

回复 3# smss
  1. "`r`n<!--smss于" + (Get-Date).ToString("yyyy年M月d日 HH:mm:ss制作-->") | out-file -filepath $file2 -appen -Enc UTF8
复制代码
把这一句放到第一个脚本的最后
作者: smss    时间: 2019-6-24 16:14

回复 4# WHY 谢谢大神




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2