grep and sed equivalent in PowerShell

后端 未结 2 518
生来不讨喜
生来不讨喜 2021-01-11 17:10

I am trying to do the following statement in PowerShell

svn info filename | grep \'^Last Changed Date:\'| sed -e \'s/^Last Changed Date: //\'
相关标签:
2条回答
  • 2021-01-11 17:37

    To remove the leading label you could use a capture group with the RegEx pattern.

    svn info filename | Select-String '^Last Changed Date: (.*)$' | ForEach-Object{$_.Matches.Groups[1].Value)
    

    Or taking Ansgars approach without the match (and repeating the label)

    (svn info filename) -replace "(?sm).*?^Last Changed Date: (.*?)$.*","`$1"
    
    0 讨论(0)
  • 2021-01-11 17:47

    Use the -match and -replace operators:

    (svn info filename) -match '^Last Changed Date:' -replace '^Last Changed Date: '
    
    0 讨论(0)
提交回复
热议问题