如何将字符串的一部分格式化为字符串 [英] How to grep a part of string form a string

查看:110
本文介绍了如何将字符串的一部分格式化为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。



我在下面给出命令

$ / abc / tej --version

输出 -

abc version = 1234R

xyz Version = P2vfs(5.1.5-1)



我想要grep上面的命令,这样我只得到5.1值。



我用/ abc / tej --version | grep ^ xyz | sed's /.*(//'| head -c 3.



任何人都可以帮助我获得更简单的命令或正则表达式来获取子串



提前致谢。

Hi.

I give below command
$ /abc/tej --version
output-
abc version = 1234R
xyz Version = P2vfs(5.1.5-1)

I want to grep the above command so that i get only 5.1 value.

I did it using /abc/tej --version | grep ^xyz | sed 's/.*(//' | head -c 3.

Can anyone help me to get a simpler command or regex to get the substring

Thanks in advance.

推荐答案

/ abc / tej --version

输出 -

abc version = 1234R

xyz Version = P2vfs(5.1.5-1)



我想要grep上面的命令,这样我只得到5.1值。



我用/ abc / tej --version | grep ^ xyz | sed's /。 *(//'| head -c 3.



任何人都可以帮助我获得更简单的命令或正则表达式以获得子串



提前谢谢。
/abc/tej --version
output-
abc version = 1234R
xyz Version = P2vfs(5.1.5-1)

I want to grep the above command so that i get only 5.1 value.

I did it using /abc/tej --version | grep ^xyz | sed 's/.*(//' | head -c 3.

Can anyone help me to get a simpler command or regex to get the substring

Thanks in advance.


作为正则表达式,它非常简单:

As a regex it's pretty simple:
(?<=Version = .*?\()\d+\.\d+(?=\.\d+-\d+\))

这篇关于如何将字符串的一部分格式化为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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