我正在尝试在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
答案 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"