PowerShell中的grep和sed等效项 [英] grep and sed equivalent in PowerShell

查看:1376
本文介绍了PowerShell中的grep和sed等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to do the following statement in 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

推荐答案

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

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)

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

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

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

这篇关于PowerShell中的grep和sed等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆