Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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. please help

share|improve this question

1 Answer 1

up vote 4 down vote accepted
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.

share|improve this answer
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

 
discard

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.