Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this command

$ cut -f2,3 AIS2F1 | grep [2-9][0-9]*  | cut -f1

So my second and third fields are something like this

Ben 434
Me  12
you 56

So, I thought that the logic should be to cut the second and third field then grep numbers that are bigger than 20 and then cut the first field. That should give me the name that is on the same line with number that is bigger than 20, but it gives me this output:


instead of


which is what I want, how can I fix this command?

share|improve this question
You need to quote your arguments to grep. That regex is also a valid shell glob, and could be expanded by the shell before grep sees it – jordanm Mar 8 '13 at 23:09
Not an answer, but awk is better suited here as well: awk '$3 ~ /[2-9][0-9]+/ { print $2 }' AIS2F1 – jordanm Mar 8 '13 at 23:11
@jordanm, no need for + or * here. Also, looks like awk '$3 >= 20 {print $2} may be even more appropriate here. – Stéphane Chazelas Mar 9 '13 at 0:48
@StephaneChazelas You are correct. – jordanm Mar 9 '13 at 0:52
up vote 3 down vote accepted

The * in grep means that zero or one of the previous occurrences will be matches. Thus, your grep command matches every line containing a [2-9]. Replace the * with a \+, which means: match one or more occurrence.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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