How to create a dictionary using cygwin

  1. The problem statement, all variables and given/known data:

Create a dictionary using cygwin. Display the following menu at the start of

execution

1-add a word in the dictionary # specify the meaning
2-search a word # if word exists, show the meaning of the word
2-delete a word
4-delete all words in the dictionary

#NOTE: The program should ask the user if he wishes to continue or not.

  1. Relevant commands, code, scripts, algorithms:

grep,awk,sed

  1. The attempts at a solution (include all code and scripts):

And here is my Code....

ans=yes
while [ $ans = yes ]
do
echo 1-Add a word in the dictionary
echo 2-Search a word in the dictionary
echo 3-Delete a word in the dictionary
echo 4-Delete all words in the dictionary
echo -n "Choose which to execute: "
read ENTRY

case $ENTRY in
1)
echo -n "Enter a word: "
read word
echo $word " " | cat >> word.txt
echo -n "Enter the meaning: "
read meaning
echo $meaning | cat >> word.txt
;;
2)
SUCCESS=0
echo -n "Enter the word to search: "
read word

grep -q "$word" "word.txt"
if [ $? -eq $SUCCESS ]
then
awk "/$word/" word.txt
else
echo Word not found!
fi
;;
3)
echo "Enter a word to delete: "
read word
grep "$word" word.txt | cat > word.txt
;;
4)
echo | cat > word.txt | echo Successfully Deleted!
;;
echo -n "Do you want to continue?yes or no: "
read ans
done

In the case 1 , I wanted that everytime I save a word & meaning to a notepad it

would appear like this in the notepad

#example

Clandestine means Secret
Loquacious means Talkative

but in my code, it appears like this in the notepad

#example

Clandestine means Secret Loquacious means Talkative

Can anybody help me with my code , especially in case 1 and case 3?

Your immediate response regarding this matter is so much appreciated

Thank you so much in advance :slight_smile: God bless ....

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

AMA COMPUTER LEARNING CENTER/GENERAL SANTOS CITY/PHILIPPINES/MS. NARIN/ PRINCIPLES OF OPERATING SYSTEM (NO LINK AVAILABLE)

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

You're almost there... small changes:
change case 1) to:

    echo -n "Enter a word: "
    read word
    echo -n "Enter the meaning: "
    read meaning
    echo "$word means $meaning" >> word.txt
    ;;

and case 3) to:

    echo "Enter a word to delete: "
    read word
    sed -i "/$word/d"
    ;;

...and case 4) to:

    >word.txt && echo "Succesfully deleted!"

...and it should work. (works for me :wink: )
ps.
You're missing keyword esac after case 4).

1 Like

weeee... Thanks for the help :slight_smile:
Even though I already fixed my project before I read this, still I appreciate your help :slight_smile:

Again Thank you so much... Take care and God bless you :slight_smile: