Reputation: 1112
I tried to do it the brute force way:
egrep '[a][a] | [b][b] | [c][c]....' file
is there any better way to do it?
Upvotes: 2
Views: 3578
Reputation: 233
You can also do this:
$ egrep '([a-z])\1' file
([a-z]) - for any character assigns it a number with in the pattern, I believe the numbering starts from 0, and then you are checking if the second letter is same as 1.
Upvotes: 2
Reputation: 137418
Use a back-reference:
egrep '(\w)\1' file
will match any two consecutive "word characters".
The (\w)
creates a "group" that matches any word character. The \1
refers to whatever was matched in the first group (which here means the previous character.
$ cat test
abcdefg
1234567
abcddefgj
88427
$ egrep '(\w)\1' test
abcddefgj
88427
Upvotes: 8