LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-14-2022, 09:39 AM   #1
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Seven-letter words with only one vowel


This is my solution.
Code:
echo; echo 'Find seven-letter words which have only one vowel.'
     Path=${0%%.*}
  OutFile=$Path"out.txt"
 WordList='/usr/share/dict/words'
   Sevens=$Path"sevens.txt"
 egrep "^.{7}$" $WordList       \
|grep -v '[^a-z]' >$Sevens
 sed 's/[^aeéiouy]//' $Sevens   \
|sed 's/[^aeéiouy]//'           \
|sed 's/[^aeéiouy]//'           \
|sed 's/[^aeéiouy]//'           \
|sed 's/[^aeéiouy]//'           \
|sed 's/[^aeéiouy]//'           \
|paste -d" " $Sevens -          \
|egrep "^.{9}$"                 \
>$OutFile
It works but seems like brute force. Is there a better, faster, cleaner method? Please advise.

Daniel B. Martin

.
 
Old 09-14-2022, 09:55 AM   #2
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Original Poster
Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
I searched my personal library and found this one.
Code:
 egrep "^.{7}$" $WordList       \
|grep -v '[^a-z]' >$Sevens

tr -dc '[aeiouéèy\n]' <$Sevens  \
|paste $Sevens -                \
|sed -nr '/^.{9}$/p'            \
>$OutFile
Daniel B. Martin

.
 
Old 09-14-2022, 11:18 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,333
Blog Entries: 3

Rep: Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730
There don't seem to be any modules or built-in character sets which include a comprehensive group of vowels, at least not externally. However, CPAN's Unicode::Normalize can convert to ASCII and then you can check with a pattern similar to one of the ones which you have used above.

Code:
#!/usr/bin/perl                                                                 
                                                                     
use Unicode::Normalize;                                                                                
use strict;                                                                     
use warnings;

while (my $s = <>) {
    if ($s =~ m/^\w{7}$/) {
        my $d = NFKD($s);
        if ($d =~ m/[aeiou]{1}/ && $d !~ m/[aeiou](?=.*[aeiou])/i) {
            print $s;
        }
    }
}

exit(0);
That reads in a line and checks if it contains a seven-letter string. Then it normalizes it to ASCII and checks for the presence of a single vowel, except for y in English and w in Welsh etc.

I think that's about as short as it can be with the Unicode constraint. If you are sticking with ASCII then sed or grep would be enough.

Edit: The old version allowed up to one vowel but did not require one. The modification requires exactly one vowel.

Last edited by Turbocapitalist; 09-14-2022 at 11:18 PM. Reason: $d =~ m/[aeiou]{1}/ && ...
 
2 members found this post helpful.
Old 09-14-2022, 10:56 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,009

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
Code:
awk -F'[aeiou]' '/^\w{7}$/ && NF == 2' $WordList
 
3 members found this post helpful.
Old 09-15-2022, 12:18 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,962

Rep: Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332Reputation: 7332
you can also try to
1. filter 7 letter words,
2. remove all the non-wovels (like your sed)
3. check length again, should be 1
but the post #3 and #4 are definitely much better. I would avoid using pipe chains if possible.
 
Old 09-15-2022, 01:28 AM   #6
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
"Holy Grail, Batman!"

I think I'll keep my inelegant solution to myself!
 
Old 09-15-2022, 07:12 AM   #7
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,807

Rep: Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207Reputation: 1207
Code:
awk '
  { u0=toupper($0) }
  length==7 && gsub(/[BCDFGHJKLMNPQRSTVWXZ]/, "", u0)==1
' "$WordList"
If you want to keep+print the vowel:
Code:
awk '
  { u0=toupper($0) }
  length==7 && gsub(/[^BCDFGHJKLMNPQRSTVWXZ]/, "", u0)==6 {
    print u0,$0
  }
' "$WordList"
 
1 members found this post helpful.
Old 09-15-2022, 11:59 AM   #8
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,678
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
Hint:

Filter for words which do match [aeéiouy] in a suitable words-file, then pipe the results to keep only those which do not match [aeéiouy].*[aeéiouy]. Finally, filter out all which are not seven-letter words. (Rearrange the order of piped operations as you like.)

A "shell one-liner," given a suitable "words file," can solve this. No programming is required.

Q.E.D.

Last edited by sundialsvcs; 09-15-2022 at 12:05 PM.
 
  


Reply

Tags
text editing



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
seven unrelated words as passphrase rblampain Linux - Security 8 02-05-2021 04:23 AM
LXer: Words, Words, Words--Introducing OpenSearchServer LXer Syndicated Linux News 0 08-07-2019 02:13 PM
LXer: OpenSSL releases seven patches for seven vulns LXer Syndicated Linux News 0 06-13-2015 07:01 AM
How do I type vowel ligatures in linux? Ole Juul Linux - General 3 09-16-2008 12:58 AM
Select only words with a letter Coimbra Linux - Newbie 6 07-04-2007 08:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:13 PM.

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