Artificial intelligent assistant

grep pattern syntax for finding words I'm trying to find all words in which my initials show up not necessarily consecutively. My first initial should start the word. My last initial should end the word. My middle initial is somewhere in between the word code: grep '^j.*x$' file ( j is first initial, t would be middle, x is the end of the word )

Well, you would start with


j.*t.*x


But the `.*` bits would match _anything_. So instead restrict those parts to only match letters:


j[[:alpha:]]*t[[:alpha:]]*x


The `[[:alpha:]]` thing is a POSIX character class that is _roughly_ the same as `[A-Za-z]`, i.e. any alphabetic character.

That's you pattern. Then ask `grep` nicely to only return complete words. You do that with the `-w` option. That would restrict the matches to substrings on each line that are delimited by non-word characters such as spaces, or at the start or end of the line.

Add `-i` if you want to do case-insensitive matching.

If you want only the bits of each line that actually matches the pattern and not the whole line, additionally use `-o`.

You'll end up with


grep -i -o -w 'j[[:alpha:]]*t[[:alpha:]]*x'


Testing:


$ grep -i -o -w 'j[[:alpha:]]*t[[:alpha:]]*x' /usr/share/dict/words
janitrix

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 4c7cec26f01256a9bdc5dbbcc509d4eb