1

This question already has an answer here:

So I'm creating a simple grep command that gets only the last logged in people who's username starts with 161 and has 3 digits next to it:

last | grep "^161[0-9]{3}"

However it doesn't print anything even though it has these usernames on the list. Whats even more weirder is if I do egrep instead of grep

last | egrep "^161[0-9]{3}"

The command works.

Can anyone explain what is the difference?

marked as duplicate by ilkkachu, Jeff Schaller, Rui F Ribeiro, roaima, telcoM Jun 4 '18 at 5:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

As steeldriver already pointed out, grep uses basic regular expressions whereas grep -E and egrep use extended regular expressions.

last | grep  '^161[0-9]\{3\}'
last | egrep '^161[0-9]{3}'

Not the answer you're looking for? Browse other questions tagged or ask your own question.