GREP How to search for words containing specific letters (one or more times)?

I am using the operating system dictionary file for scanning. I am creating a java program that allows the user to enter any mixture of letters to find words containing these letters. How can I do this with grep commands?

+3
source share
2 answers

To find words containing only the specified letters:

grep -v '[^aeiou]' wordlist

The above filters highlight lines in wordlistthat do not contain any characters other than those listed. This is a kind of use of double negativity to get what you want. Another way to do this:

grep '^[aeiou]+$' wordlist

which searches the entire string for a sequence of one or more selected letters.

, , , , , :

cat wordlist | grep a | grep e | grep i | grep o | grep u

(, cat , .)

+3

grep , grep PCRE. ( , )

grep -P "(?=.*a)(?=.*e)(?=.*i)(?=.*o)(?=.*u)" wordlist

lookahead , "a" "e" ... .. ..

0

All Articles