Continuing my quest to learn BASH, Bourne, Awk, Grep, etc. on my own through the use of a few books. I've come to an exercise that has me absolutely stumped.
The specifics:
1. Using ONLY BASH scripting commands (not sed, awk, etc.), write a script to convert a string on the command line to Morse code. The script will handle only capital letters and numbers
2. It will convert the string given on the command line as in the
following example:
$ ./morse.bash “CAT IN”
-.-.,.-,-,SP,..,-.,EOT (SP is used for a space, and EOT for end of transmission).
3. An associative array is to be used for the “lookup table” to do the
conversion from a character to Morse Code.
This is my time using an associative array, so this exercise has me stumped. Any help, guidance, suggestions are greatly appreciated. Here's what I have so far:
...
If i did, it was by accident just because i had fun and got excited as it was and is also a challenge to me.
And it is a communication tool, so the 'encoding' must be possible both ways.
Ok, vice-versa encoding is working now:
This stuff is really a good training excercise for shuffeling and parsinge strings and chars.
But by now, WAY too many hours invested in this, mostly just to get the output/handling as it looks now...
Play with it, change the usage of the function morse2char to be using the letter["..."] array.
Make your own experiments.
Make one script to encode, and another to decode, then try to combine them.
I've run into one small issue with the space (SP) character. On the command line, if I type ./morse.bash "CAT IN" the output is -.-.,.-,-,SP..,-.,EOT. I can't figure out why two .. are following the SP. Here's my code:
This one accepts input from a pipe or interactive stdin or with a filename as argument. See Usage:
I'm struggling with strings as arguments to the command. It throws an error if $1 is not a filename. I managed to get it to accept option "-h", but dictionary words don't fly (yet).
Last edited by ongoto; 12-02-2014 at 04:15 AM..
Reason: re-wrote parts to better handle 'SP'
Barry, i couldnt resist and made some changes
Also, after some tries, figured, i cannot differ signs (.-) from chars (a-z) or words, without the use of some delaying sleep calls...
Hello.
I have an export of an associative array build using declare -p SOME_ARRAY_NAME > SOME_FILE_NAME.txt.
Producing some thing like declare -A SOME_ARRAY_NAME=( ="some_text" ="a_text" ......... ="another_text" ) in a text file.
I have a stock of functions which are sourced from... (1 Reply)
I am trying to assign indexes to an associative array in a for loop but I have to use an eval command to make it work, this doesn't seem correct I don't have to do this with regular arrays
For example, the following assignment fails without the eval command:
#! /bin/bash
read -d "\0" -a... (19 Replies)
Hello together,
i make something wrong... I want an array that contains information to associate it for further processing.
Here is something from my bash... You will know, what I'm trying to do.
I have to point out in advance, that the variable $SYSOS is changing and not as static as in my... (2 Replies)
Hi all
I have a problem where i have a large list ( up to 1000 of items) and need to have 2 items pulled from it into variables in a bash script
my list is like the following and I could have it as an array or possibly an external text file maintained separately. Every line is different and... (6 Replies)
I have an associative array named table
declare -A table
table="fruit"
table="veggie"
table="GT"
table="eminem"
Now say I have a variable returning the value highway
How do I find corresponding value GT ??
(this value that I find (GT in this case) is supposed to be the name of a mysql... (1 Reply)
Hi All,
I got stuck up with shell script where i use awk. The scenario which i am working on is as below.
I have a file text.txt with contents
COL1 COL2 COL3 COL4
1 A 500 400
1 B 500 400
1 A 500 200
2 A 290 300
2 B 290 280
3 C 100 100
I could able to sum col 3 and col4 based on... (3 Replies)
i have a file like this
< '393200103052';'H3G';'20081204'
< '393200103059';'TIM';'20110111'
< '393200103061';'TIM';'20060206'
< '393200103064';'OPI';'20110623'
> '393200103052';'HKG';'20081204'
> '393200103056';'TIM';'20110111'
> '393200103088';'TIM';'20060206'
Now i have to generate a file... (9 Replies)
Most shells flavors do not have associative arrays a.k.a. maps.
How would you emulate an associative array?
I had this problem once and found a working solution, but I don't want to spoil the game hence I wont tell it.
Wonder if anyone comes up with something better. (5 Replies)
Hi,
When using sort on an associative array:
foreach $key (sort(keys(%opalfabet))){
$value = $opalfabet{$key};
$result .= $value;
}
How does it handle double values?
It seems to me that it removes them, is that true? If so, is there a way to get... (2 Replies)
Hi,
I am trying to make an associative array to use in a popup_menu on a website. Here is what i have:
foreach $entr ( @entries )
{
$temp_uid = $entr->get_value(uid);
$temp_naam = $entr->get_value(sn);
$s++;
}
This is the popup_menu i want to use it in.
popup_menu(-name=>'modcon',... (4 Replies)