【问题标题】:PowerShell Split Select StringPowerShell 拆分选择字符串
【发布时间】:2019-01-29 10:41:48
【问题描述】:

我有以下命令

Get-ChildItem -Recurse -Path 'C:\root' | Select-String -Pattern '172\.20\.' | group | select name | export-csv -Path 'C:\test.csv'

此命令遍历 .zone 文件并返回文件的路径和匹配我的模式的字符串。

问题是,结果是这样的:

name
C:\root\test.com.zone:22:test.com.900 IN TXT "v=spf1 mx ptr ip4:172.20.1.1 -all"

如何拆分结果,以便我首先拥有我的文件名和不同列中的值?这是必需的,因为我无法将它们拆分为 .csv 文件

【问题讨论】:

    标签: powershell split select-string


    【解决方案1】:

    你不需要分组:

    Get-ChildItem -Recurse -Path 'C:\root' | 
     Select-String -Pattern '172\.20\.' | 
       select Path,Linenumber,Line | 
         export-csv -Path 'C:\test.csv'
    

    带分组

    【讨论】:

      猜你喜欢
      • 2018-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-21
      • 1970-01-01
      • 2019-12-16
      • 2013-09-26
      • 1970-01-01
      相关资源
      最近更新 更多