std
std

Reputation: 963

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 '[[:digit:]]\-[[:digit:]]' mydoc

It is ok to grep "1-9" but I can't figure out how to grep other two patterns!

Upvotes: 1

Views: 915

Answers (2)

mkjeldsen
mkjeldsen

Reputation: 2180

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

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

?

Upvotes: 1

user unknown
user unknown

Reputation: 36229

The minus needs no masking. + allows multiple occurrences.

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

Upvotes: 2

Related Questions