i have path name as below,

  1. abc4/2012
  2. abc4/2013
  3. abc45/2014
  4. abc45/2014

When i grep for 45 it is showing one instance of 4 and for 4 its showing all 45. i need to grep both single digit and double digit separately.

egrep '([^0-9]4[^0-9]|[^0-9]45[^0-9])'

Does it for me - that is, 4 surrounded by non-digits, or 45 surrounded by non-digits.

  • 1
    There are also named classes (at least in GNU grep) in the form of [:class_name:], e.g. [^0-9] can be written as [^[:digit:]] - this can be useful when grepping in non-POSIX locales (and when grepping for something else than numbers obviously). – peterph Dec 19 '13 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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