Sponsored Content
Full Discussion: Scrabble (SED)
Top Forums UNIX for Dummies Questions & Answers Scrabble (SED) Post 302602883 by iFaceDive on Tuesday 28th of February 2012 02:51:21 PM
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
 

4 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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
Locale::Codes::LangFam(3)				User Contributed Perl Documentation				 Locale::Codes::LangFam(3)

NAME
Locale::Codes::LangFam - standard codes for language extension identification SYNOPSIS
use Locale::Codes::LangFam; $lext = code2langfam('apa'); # $lext gets 'Apache languages' $code = langfam2code('Apache languages'); # $code gets 'apa' @codes = all_langfam_codes(); @names = all_langfam_names(); DESCRIPTION
The "Locale::Codes::LangFam" module provides access to standard codes used for identifying language families, such as those as defined in ISO 639-5. Most of the routines take an optional additional argument which specifies the code set to use. If not specified, the default ISO 639-5 language family codes will be used. SUPPORTED CODE SETS
There are several different code sets you can use for identifying language families. A code set may be specified using either a name, or a constant that is automatically exported by this module. For example, the two are equivalent: $lext = code2langfam('apa','alpha'); $lext = code2langfam('apa',LOCALE_LANGFAM_ALPHA); The codesets currently supported are: alpha This is the set of three-letter (lowercase) codes from ISO 639-5 such as 'apa' for Apache languages. This is the default code set. ROUTINES
code2langfam ( CODE [,CODESET] ) langfam2code ( NAME [,CODESET] ) langfam_code2code ( CODE ,CODESET ,CODESET2 ) all_langfam_codes ( [CODESET] ) all_langfam_names ( [CODESET] ) Locale::Codes::LangFam::rename_langfam ( CODE ,NEW_NAME [,CODESET] ) Locale::Codes::LangFam::add_langfam ( CODE ,NAME [,CODESET] ) Locale::Codes::LangFam::delete_langfam ( CODE [,CODESET] ) Locale::Codes::LangFam::add_langfam_alias ( NAME ,NEW_NAME ) Locale::Codes::LangFam::delete_langfam_alias ( NAME ) Locale::Codes::LangFam::rename_langfam_code ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangFam::add_langfam_code_alias ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangFam::delete_langfam_code_alias ( CODE [,CODESET] ) These routines are all documented in the Locale::Codes::API man page. SEE ALSO
Locale::Codes The Locale-Codes distribution. Locale::Codes::API The list of functions supported by this module. http://www.loc.gov/standards/iso639-5/id.php ISO 639-5 . AUTHOR
See Locale::Codes for full author history. Currently maintained by Sullivan Beck (sbeck@cpan.org). COPYRIGHT
Copyright (c) 2011-2013 Sullivan Beck This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.16.3 2013-02-27 Locale::Codes::LangFam(3)
All times are GMT -4. The time now is 09:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy