简体   繁体   English

如何在shell中使用regular-expression来grep这个模式?

[英]How do I grep this pattern with regular-expression in shell?

I want to grep the pattern like "1-10","10-20","1-9"(without double quotes) with the following code: 我想使用以下代码grep模式如“1-10”,“10-20”,“1-9”(不带双引号):

grep '[[:digit:]]\-[[:digit:]]' mydoc

It is ok to grep "1-9" but I can't figure out how to grep other two patterns! grep“1-9”是可以的,但我无法弄清楚如何grep其他两个模式!

The minus needs no masking. 减号不需要掩盖。 + allows multiple occurrences. +允许多次出现。

egrep '[0-9]+-[0-9]+' mydoc

grep -E '[[:digit:]]+-[[:digit:]]+' mydoc

grep -E '[[:digit:]]{1,2}-[[:digit:]]{1,2}' mydoc

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

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