I am working through a lab on RegEx which asks me to:
Search the 'countries' file for all the words with nine characters and the letter i.
How many results are found?
I am working in a generic Linux command prompt in a online emulated environment. I am allowed to use grep
, awk
or sed
though I am feeling a preference for grep
.
(I am 100% a noob when it comes to RegEx so please explain it to me like I'm 5)
Per a previous lab I already used something like below which finds me all countries which have 9 characters, however I cannot find a way to make it find all words which have 9 characters AND contain the letter i
in any position.
grep -E '\b\w{9}\b' countries
The |
operator does not help because its an OR
operator and will find me all instances that i
is found, and all words which are 9 characters and I need both to happen at the same time. I tried multiple grep
statements as well and it seems the emulator may not accept that.
I am also trying to stick to []
character sets as the next question asks for multiple letters within the 9 letter word.