1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Rep Power

    Unhappy Linux small command-line script

    Okay so i had to create a small script to remove all the vowels from whatever word is entered after i run the script.
    for example.

    ./devowel hamburger

    I have this script working perfectly. But i also need to make a script that takes input like the "hmbrgr"
    and adds the vowels back to make a word.
    so the script shoud run like.
    ./revowel hmbrgr

    my initial idea was to just take that input and add it to a grep and grep though a dictionary and output all the words that have those consonants in it but im having trouble getting it to search for all of the letters. The script only searches for words that have any one of the letters, not all of them anywhere inside the word.

    any ideas or help is appreciated, thank you
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Rep Power
    Here are three ways to approach the problem:

    The transformation takes "bat" or "bit" and converts it to "bt". To find the original you need to look for the word with the removed vowels "b[ai]t". Extend that regex for all removed letters, multiple removed letters, no removed letters, more than two consonants, etc.

    Create a lookup table from the dictionary be reformatting it as [word-without-consonants][space][word-with-consonants]. If the first column matches, the second column is the original word.

    For each word in the dictionary, remove the vowels and compare with the input. Output the unmodified word from the dictionary when they match.

    If you're allowed to use it, it would be easiest to solve this using perl. Otherwise you may find the "sed" and "awk" tools useful.
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);

IMN logo majestic logo threadwatch logo seochat tools logo