Reputation: 963
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
Reputation: 2180
grep -E '[[:digit:]]+-[[:digit:]]+' mydoc
grep -E '[[:digit:]]{1,2}-[[:digit:]]{1,2}' mydoc
?
Upvotes: 1
Reputation: 36229
The minus needs no masking. + allows multiple occurrences.
egrep '[0-9]+-[0-9]+' mydoc
Upvotes: 2