Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grep : Find occurances of 3 consecutive alphabets

Tags:

grep

sed

I want to find aaa, bbb etc I've tried :

grep -E [a-z]\{3\} 1.txt

but this even prints abc

like image 470
Mukul Shukla Avatar asked Dec 09 '25 22:12

Mukul Shukla


1 Answers

You can use references to capturing groups:

[/tmp] cat test.txt                                                            
aaa
bbb
abc
aab
bbc
[/tmp] grep -E "([a-z])\1{2}" test.txt                                         
aaa
bbb

\1 refers to the stuff captured by ([a-z]) (a single letter, in your case), so the regex looks for a single letter followed by the same letter two more times.

like image 194
Blender Avatar answered Dec 11 '25 14:12

Blender



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!