You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改Select-String输出格式:将行号置于路径括号内

修改Select-String输出格式的方法

原输出格式:

\\path-to-logfile\copy2xl.log:390:NOTE: At least one W.D format was too small for the number to be printed. The decimal may be shifted by the "BEST" format.

目标输出格式:

\\path-to-logfile\copy2xl.log(390):NOTE: At least one W.D format was too small for the number to be printed. The decimal may be shifted by the "BEST" format.

可以通过PowerShell管道结合ForEach-Object重构输出内容,具体命令如下:

# 替换为你的目标文件路径和匹配模式
Select-String -Path "\\path-to-logfile\copy2xl.log" -Pattern "W.D format was too small" | ForEach-Object {
    # 按目标格式拼接路径、行号和行内容
    "$($_.Path)($($_.LineNumber)):$($_.Line)"
}

核心逻辑:

  • Select-String返回的匹配对象自带Path(文件路径)、LineNumber(行号)、Line(匹配行内容)属性
  • 通过字符串插值将这三个属性按路径(行号):行内容的格式重新组合,即可得到目标输出

内容的提问来源于stack exchange,提问作者data null

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 18:42:34