powershell - PowerShell Select-String 导致 Esc 字符
问题描述
我正在尝试将一些日志组合在一起并仅选择具有高欠载 (u:) 的行。任何超过 0 的都是高的。该代码在终端内创造了奇迹。但是,当我将信息推送到文件时,我得到的是 ESC 字符而不是信息。
$Files = get-childitem C:\Tmp
$Underruns = foreach ($file in $Files) {
$File | get-content | Select-String -Pattern ",u:[1-9].*,o:"
}
$Underruns | Out-File -Encoding utf8BOM -FilePath c:\tmp\combined.txt
上面的代码是添加转义字符。这些字符正在阻止代码的流动。我怎样才能防止这种情况发生?
(j:0[7m,u:15424,o:[0m0)
感谢您的帮助。
解决方案
经过一些挖掘解决方案是选择字符串上的 -Raw 标志。
$Files = get-childitem C:\Tmp
$Underruns = foreach ($file in $Files) {
$File | get-content | Select-String -Pattern ',u:[1-9].*,o:' -Raw
}
$Underruns | Out-File -Encoding utf8BOM -FilePath c:\tmp\combined2.txt
推荐阅读
- android - 如何将android应用程序连接到postgresql
- python - 求解隐式方程 Python
- android - 如何在 Android P 或更高版本电池耗尽时接收 ACTION_SHUTDOWN
- java - Android 应用程序 - 将传感器数据保存到本地文件
- flutter - 堆栈小部件内的 Flutter 定位类,不接受子属性
- sql-server - 获取另一个SP中的SP返回的Second Table Set
- javascript - Electron, Javascript 主进程发生错误
- html - 寻求建议 - 实现按钮以更改显示的文本
- r - 当缺少条时,如何避免条在分组图中变宽?
- reactjs - React.js 使用链接表选择