Scrabble (SED)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Scrabble (SED)
# 1  
Old 02-28-2012
Scrabble (SED)

Hello everyone,

I've been struggling with an assignement for school for quite some time now and I decided to make a thread here. The goal of the script is to return all the words that can be created with a certain combination of letters that can be given as an argument for the shellscript. It's not necessary that the all these letters are used, but every letter can be used only once.

They also gave us some guidelines on how to make this script :
-> Save the first word (the combination of letters) in the hold space, so you can use it later on
-> For all other words you make a copy of the word in the pattern space, and separate it from the original worth with a verical line ( | )
-> Add the hold space to the pattern space
-> Use a loop in sed that erases both a letter from the duplicate as from the combination of letters till all the letters of the duplicate are used or till there are no corresponding letters
-> Only write the original version of the word (the word before the |) if all the letters behind the | are gone.

I know this is a lot of text, but here is some code to make up for it Smilie

Code:
    $ scrabble scriptingtalen
    actie
    scrabble

    agent
    derive

    general

    alen
    alge
    belgium

    alpinist
    breakfast

    alpinisten

This will turn into this :

Code:
    $ scrabble scriptingtalen
     actie|actie
     scrabble|scrabble

     agent|agent
     derive|derive

     general|general

     alen|alen
     alge|alge
     belgium|belgium

     alpinist|alpinist
     breakfast|breakfast

     alpinisten|alpinisten

And eventually :

Code:
    $ scrabble scriptingtalen
     actie
      agent
       alen
     alge
      alpinist
      alpinisten

I already found this part of the code :

Code:
#!/bin/bash

WOORDENLIJST='./woordenlijst.txt'

echo $1 | cat - ${WOORDENLIJST} | sed -nf sedscript 

---------
sedscript
---------
1h
2,${
s/.*/&|&/
G
:a
s/\(.*\)|\(.\)\(.*\)\n\(.*\)\2\(.*\)/\1|\3\n\4\5/
ta
/|$/s/\(.*\)|$/\1/
P
}

I'm speak Dutch and the "woordenlijst.txt" document is a file which contains a couple of thousands of words.

There are still some faults in my code and I'd like to have them pointed out, or to get a better solution to solving this exercise.

Thanks in advance,
iFaceDive
# 2  
Old 02-28-2012
Hi.

Please post classroom or homework problems in our homework forum (using the guidelines for posting there).

Many thanks.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I am learning regular expression in sed,Please help me understand the use curly bracket in sed,

I am learning SED and just following the shell scripting book, i have trouble understanding the grep and sed statement, Question : 1 __________ /opt/oracle/work/antony>cat teledir.txt jai sharma 25853670 chanchal singhvi 9831545629 anil aggarwal 9830263298 shyam saksena 23217847 lalit... (7 Replies)
Discussion started by: Antony Ankrose
7 Replies

2. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

3. UNIX for Dummies Questions & Answers

Scrabble Regex Help

Hi! I use an and grep to play Scrabble and other word games because it helps me practice regexes, or, as my friends would say, because I'm a cheater. Anyway, I'm trying to work out how to write a regex that might do what I want, so let's see if I can explain it properly. Let's say we want to play... (3 Replies)
Discussion started by: sudon't
3 Replies

4. Shell Programming and Scripting

sed over writes my original file (using sed to remove leading spaces)

Hello and thx for reading this I'm using sed to remove only the leading spaces in a file bash-280R# cat foofile some text some text some text some text some text bash-280R# bash-280R# sed 's/^ *//' foofile > foofile.use bash-280R# cat foofile.use some text some text some text... (6 Replies)
Discussion started by: laser
6 Replies
Login or Register to Ask a Question