regex - How to match only odd occurrences of a character at the end of the line using grep -


for example, i'm matching odd occurrences of 'a'. "helloaaa" should match while "helloaaaa" should not match.

i've tried "(aa)*a$" , without -e option on bash.

your problem helloaaaa matches because of last 3 as:

helloaaaa       === 

to avoid need make sure previous character not a:

grep -e '[^a](aa)*a$' filename 

here i'm assuming line isn't entirely as. if entire line can as can use regular expression instead:

grep -e '(^|[^a])(aa)*a$' filename 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -