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
Post a Comment