1

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!

2 Answers 2

2

The minus needs no masking. + allows multiple occurrences.

egrep '[0-9]+-[0-9]+' mydoc
Sign up to request clarification or add additional context in comments.

Comments

1

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

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

?

1 Comment

afaik, the '-' needs no masking.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.