PowerShell中的grep和sed等效项

时间:2018-12-20 10:48:33

标签: linux powershell svn

我正在尝试在PowerShell中执行以下语句

svn info filename | grep '^Last Changed Date:'| sed -e 's/^Last Changed Date: //'

我已经尝试过了:

svn info filename | Select-String '^Last Changed Date:'

我期望低于输出

Thursday, December 20, 2018 4:50:40 AM

2 个答案:

答案 0 :(得分:3)

使用-match-replace operators

(svn info filename) -match '^Last Changed Date:' -replace '^Last Changed Date: '

答案 1 :(得分:2)

要删除开头的标签,您可以使用具有RegEx模式的捕获组。

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

或者在没有匹配的情况下采用Ansgars方法(并重复标签)

(svn info filename) -replace "(?sm).*?^Last Changed Date: (.*?)$.*","`$1"