LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-26-2009, 01:05 PM   #1
SSlide
LQ Newbie
 
Registered: Nov 2009
Posts: 3

Rep: Reputation: 0
egrep question


Hi,

I'm new to linux and have been figuring out some of the basics lately. Though I'm stuck with egrep now.

I need to extract all words from a dictionnary list which have an odd number of consonants. The thing is I can't figure out how to do that since I'm only aware of a way to count letters/numbers consecutively.

for instance:

egrep '[^aeiou]{5}' /usr/share/dict/dutch

so my question is how can i adjust my regex to make it not look for those consonants consecutively?


thanks!
 
Old 11-26-2009, 01:38 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Hi,

welcome to LQ!

And I don't think you can. You're going to have to use a two-step approach.

One (admittedly not very elegant) solution:
Code:
sed 'p; s/[^aeiou]//g' /usr/share/dict/words | awk '{if(NR>1){if(NR%2==0){if(length($0) == 8 ){print previous}}};previous=$0}' 
anticoagulation
antiredeposition
artificialities
authoritarianism
autobiographical
autobiographies
autocorrelation
autofluorescence
autosuggestibility
availabilities
axiomatization
axiomatizations
beautifications
canonicalization
conceptualization
conceptualizations
counterintuitive
counterrevolution
disqualification
electroencephalogram
electroencephalograph
electroencephalography
familiarization
heterogeneousness
incompatibilities
industrialization
inevitabilities
inhomogeneities
initialization
initializations
institutionalize
institutionalized
institutionalizes
institutionalizing
intercommunication
miniaturization
nationalization
parameterization
parameterizations
rationalization
rationalizations
reproducibilities
revolutionaries
telecommunication
telecommunications
unidirectionality


Cheers,
Tink
 
Old 11-27-2009, 08:24 AM   #3
SSlide
LQ Newbie
 
Registered: Nov 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you sir, I just needed to know if there was a way to put it in the regex. Now I know there's not, so I'll use another approach similar to yours.
 
Old 11-27-2009, 10:59 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Welcome ... but I didn't say it's impossible. I just said I don't
think so. Chances are there's a regex guru just around the corner
who knows a fabulously cunning way of doing it :}
 
Old 11-28-2009, 03:08 AM   #5
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360

Rep: Reputation: 170Reputation: 170
Try
Code:
vow="[aeiou'./-]"                   # A vowel etc. character
con='[bcdfghjklmnpqrstvwxyz]'       # A consonant character

egrep -i "^$vow*$con$vow*($con$vow*){2}*$" /usr/share/dict/words
The extra './- characters with the vowels are there to match entries in the dictionary list such as:-

contrib.
rock-'n'-roll
roll-on/roll-off
Y.M.C.A.

Last edited by Kenhelm; 11-28-2009 at 03:26 AM. Reason: Changed (($con$vow*){2})* to ($con$vow*){2}*
 
Old 11-28-2009, 04:36 AM   #6
SSlide
LQ Newbie
 
Registered: Nov 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Damn that changes my perspective Thanks a lot, I learned a lot from that little piece of code.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
egrep question graziano1968 Linux - General 1 05-29-2007 08:28 AM
egrep/grep regex question buldir Programming 7 05-08-2006 07:17 PM
egrep question internal_war Linux - Newbie 6 05-05-2005 06:32 PM
Help with egrep smart_sagittari Linux - Newbie 2 05-02-2005 08:18 AM
Using egrep Barbarian Programming 5 10-20-2002 02:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration