imanshu15
imanshu15

Reputation: 764

How do I grep for all words that are more than 6 characters and without any vowel letters?

I found that this could specify a certain length grep -o -w '\w{6,10}' data

But I want to find all the words which contains 6 or more than 6 letter and with no any vowel letters.

Upvotes: 0

Views: 3106

Answers (2)

RomanPerekhrest
RomanPerekhrest

Reputation: 92854

grep approach to find all the words(alphanumeric sequences) containing 6 or more letters except vowels:

data file contents:

some text with vowels and CNN_tvs chars swwwdfrgcc done ...

grep -Eio '\b[b-df-hj-np-tv-z0-9_]{6,}\b' data

The output:

CNN_tvs
swwwdfrgcc

\b - points to word boundary

b-df-hj-np-tv-z - the range of consonant letters


alternative perl approach:

perl -nle 'print for /\b[b-df-hj-np-tv-z0-9_]{6,}\b/gi' data

Upvotes: 2

Kuu Aku
Kuu Aku

Reputation: 320

You could combine all your requirement in one single regex.

^(?i)[^aeiouy]{6,10}$

Explanation : ^ means at the beginning means that there can't be anything before the pattern. The string as to begin with the pattern. (?i) means being case insensitive. [^aeiouy] are strings that do not contains vowels (not is ^) {6,10} is {minlenght, maxlenght) $ means there can't be anything after the match

Use it in your grep.

Upvotes: -1

Related Questions