简体   繁体   English

带grep的RegEx for Linux

[英]RegEx with grep for Linux

Need some help at the command line running CentOS, but ultimately will be used on a Linux build. 在运行CentOS的命令行上需要一些帮助,但最终将在Linux构建上使用。 I've looked on the forum here and have tried a RegEx builder tool and I know the sytax for regex is right, but obviously it's not working. 我在这里查看过论坛,并尝试了RegEx构建器工具,并且我知道regex的语法正确,但显然无法正常工作。

options with the following have been tried in various combinations, not all together. 具有以下选项的选项已经以各种组合(而不是全部组合)进行了尝试。 ioFE ioFE

3 packets transmitted, 3 received, 0% packet loss, time 2002ms ping -c 3 192.168.0.113 | grep '(?<=received,)(.*)(?=,)'

I feel this should work, but not sure what is missing given what I know about regex. 我认为这应该可行,但是由于我对正则表达式有所了解,所以不确定是否缺少什么。 What am I doing wrong? 我究竟做错了什么?

Updated. 更新。 Two answers provided that both work: 提供了两个答案,可以同时起作用:

ping -c 3 192.168.0.113 | grep -Po '(?<=received,)(.*)(?=,)'

ping -c 3 192.168.0.113 | grep -Po 'received,\\K[^,]+'

grep -P '(?<=received,)(.*)(?=,)'

You will have to enable -P mode for that regex to work.Your regex is correct. 您必须启用-P模式才能使该正则表达式正常工作。您的正则表达式正确。 See here 看这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM