It is currently Thu May 24, 2018 5:13 pm

Find all five letter words.

All times are UTC - 6 hours

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Fri Nov 06, 2009 11:06 am   

Joined: Fri Nov 06, 2009 11:04 am
Posts: 1
Hey guys, I love this forum so far :)

I need a shell script to find all five letter words from the standard dictionary that have a single letter duplicated (the other 3 letters should not be duplicated). The output should include the five letter word followed by a “-“ and the duplicated letter, followed by a “-“ and the three non duplicate letters sorted in ascending order.


 PostPosted: Mon Nov 30, 2009 2:20 am   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!

The 'one duplicated letter' problem is not particularly fun to solve with regular expressions, or even bash, for that matter -- it would be easier to use a full programming language. Perl would be particularly easy to use, in this case.

I would do this:
    1. Run the dictionary through sed to only leave five letter words.
    2. Run a perl script to only leave words that have only one duplicated letter.

For the perl script, I would use a hash ( with the letters as a key and the number of occurrences as the value. Then, scan through the hash and check to see if only one value is >= 2. If that is the case, split out the characters as necessary, sort the other three characters with three conditional swaps, and print the output in the format you want.

This sounds like either homework to me or a bizarre analysis of the English language. What are you using this for?

- thobbs

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours

Who is online

Users browsing this forum: No registered users and 7 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  

BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group