Grepping Words with No Vowels


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grepping Words with No Vowels
# 1  
Old 02-26-2013
Grepping Words with No Vowels

Hi!
I was trying to grep all the words in a wordlist, (twl), with no vowels. I had a hard time figuring out how to do it, but I finally lit on the -v flag. Here's my question:
Why does this work:
Code:
grep -v '[aeiou]' twl

But this doesn't:
Code:
grep '[^aeiou]' twl

In the second example, we're asking for lines which do not contain that class of letters, in this case the vowels, right? To my mind, it should come out the same. Clearly I'm missing something fundamental.
# 2  
Old 02-26-2013
Read them like this:

grep lines without a 'vowel'

grep lines with a 'non-vowel'
This User Gave Thanks to MadeInGermany For This Post:
# 3  
Old 02-26-2013
Quote:
Originally Posted by MadeInGermany
Read them like this:

grep lines without a 'vowel'

grep lines with a 'non-vowel'
Ok, I see. So in the second case, any line which contains a non-vowel returns 'true'. I guess we could use the -v flag there, and get vowels only.
Thanks!
# 4  
Old 02-26-2013
Quote:
Originally Posted by sudon't
Code:
grep -v '[aeiou]' twl

Without -v:
Code:
grep '^[^aeiou]*$' twl

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 5  
Old 02-27-2013
Quote:
Originally Posted by alister
Without -v:
Code:
grep '^[^aeiou]*$' twl

Regards,
Alister
It works, of course, but I would've thought the asterisk modifier, like some other things I tried, would return almost every line. Because if it goes through a line, and comes across a vowel, isn't that an instance of zero times, returning a "true"? Obviously, that's not what happens. I'm just not sure why. One of the ways I tried it, was with a "+" to say "at least one instance."
Also, I didn't think to "cap-off" the expression with a caret and dollar, but now I see why that's necessary.
# 6  
Old 02-27-2013
Note that my pattern is anchored at both ends by ^ and $. That means that the entire line must consist exclusively of 0 or more non-vowels.

Regards,
Alister
# 7  
Old 02-27-2013
grep uses REGEX.
In REGEX the * means the previous character can be repeated zero...many times.
A previous [^aeiou] is a 'non-vowel' character.
[^aeiou]* is any repetition of a 'non-vowel'.
The ^ at the beginning is 'beginning of line', and $ at the end means 'end of line'.
So you read the entire thing as

grep lines with any repetition of a 'non-vowel' between the beginning and the end of the line.

In other words: no other characters are allowed.
This User Gave Thanks to MadeInGermany For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace particular words in file based on if finds another words in that line

Hi All, I need one help to replace particular words in file based on if finds another words in that file . i.e. my self is peter@king. i am staying at north sydney. we all are peter@king. How to replace peter to sham if it finds @king in any line of that file. Please help me... (8 Replies)
Discussion started by: Rajib Podder
8 Replies

2. Programming

Pure C function pointer on printing vowels twice

Have difficulty to understand this pure C code to only print vowels twice from input string. Questions are commented at the end of each place. #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <limits.h> /* *Demonstrate the use of dispatch tables */ /*Print a char... (11 Replies)
Discussion started by: yifangt
11 Replies

3. Shell Programming and Scripting

Search words in any quote position and then change the words

hi, i need to replace all words in any quote position and then need to change the words inside the file thousand of raw. textfile data : "Ninguno","Confirma","JuicioABC" "JuicioCOMP","Recurso","JuicioABC" "JuicioDELL","Nulidad","Nosino" "Solidade","JuicioEUR","Segundo" need... (1 Reply)
Discussion started by: benjietambling
1 Replies

4. UNIX for Dummies Questions & Answers

Replace the words in the file to the words that user type?

Hello, I would like to change my setting in a file to the setting that user input. For example, by default it is ONBOOT=ON When user key in "YES", it would be ONBOOT=YES -------------- This code only adds in the entire user input, but didn't replace it. How do i go about... (5 Replies)
Discussion started by: malfolozy
5 Replies

5. Shell Programming and Scripting

Gawk gensub, match capital words and lowercase words

Hi I have strings like these : Vengeance mitt Men Vengeance gloves Women Quatro Windstopper Etip gloves Quatro Windstopper Etip gloves Girls Thermobite hooded jacket Thermobite Triclimate snow jacket Boys Thermobite Triclimate snow jacket and I would like to get the lower case words at... (2 Replies)
Discussion started by: louisJ
2 Replies

6. Shell Programming and Scripting

How count the number of two words associated with the two words occurring in the file?

Hi , I need to count the number of errors associated with the two words occurring in the file. It's about counting the occurrences of the word "error" for where is the word "index.js". As such the command should look like. Please kindly help. I was trying: grep "error" log.txt | wc -l (1 Reply)
Discussion started by: jmarx
1 Replies

7. Shell Programming and Scripting

Grepping a list of words from one file in a master database of homophones

Hello, I am sorry if the title is confusing, but I need a script to grep a list of Names from a Source file in a Master database in which all the homophonic variants of the name are listed along with a single indexing key and store all of these in an output file. I need this because I am testing... (4 Replies)
Discussion started by: gimley
4 Replies

8. UNIX for Dummies Questions & Answers

Counting vowels in string. "Comparison pointer-integer".

I'm trying to write a programme which scans strings to find how many vowels they contain. I get an error saying that I'm trying to compare a pointer and an integer inif(*v == scanme){. How can I overcome this ? Also, the programme seems to scan only the first word of a string e.g.: if I type "abc... (1 Reply)
Discussion started by: fakuse
1 Replies

9. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

10. Shell Programming and Scripting

Number of Vowels

Hi Guys, It may look silly, but I am stuck on it and need some help How to count number of vowels in a text file Regards, Gaurav Goel (14 Replies)
Discussion started by: gauravgoel
14 Replies
Login or Register to Ask a Question