This is a simple exercise that demands to create a Bash script that provides statistics on the use of characters in a language.
NB: The French language is chosen.
Therefore, a dico.txt file is provided. This file contains all French words, one word per line, totally with uppercase characters:
ABAISSA
ABAISSABLE
ABAISSABLES
ABAISSAI
ABAISSAIENT
[...]
- The first mission is to extract the number of words using each letter of alphabet. The script will take as parameter the name of the dictionary file (dico.txt).
- The second mission is to create additional functionnality for your script. This feature can be activated by the presence of a second parameter of your own choice.
No requirements for Linux users.
For Windows users:
- Vagrant
- VirtualBox
It is recommended that Windows users use the Git Bash terminal
For Windows users:
-
Download an install Vagrant and VirtualBox.
-
Clone the repository or download it.
-
Open your Git Bash terminal to the project folder.
-
Run
vagrant up
to install the linux OS. -
Then run
vagrant ssh
. -
Then change directory to access your shared files by running
cd /vagrant
. -
Finally run the following command:
./langstat.sh dico.txt
For Linux users:
-
Clone the repository or download it.
-
Run the following command:
./langstat.sh dico.txt
The output sould be like:
278814 - E
229938 - A
219131 - I
210391 - R
207889 - S
179165 - N
176030 - T
158282 - O
[...]
To achieve the second mission, you can insert a second parameter when running the script:
-
To display result in ascending order, type:
./langstat.sh dico.txt --ascending
Output:
529 - W 1595 - K 5743 - J 8262 - X 11030 - Y 16340 - Q 30562 - V 34982 - Z [...]
-
To sort result by characters, type:
./langstat.sh dico.txt --char
Output:
229938 - A 43471 - B 98832 - C 72481 - D 278814 - E 36777 - F 48942 - G 35940 - H [...]
-
To sort result by characters in reversed way, type:
./langstat.sh dico.txt --rchar
Output:
Z - 34982 Y - 11030 X - 8262 W - 529 V - 30562 U - 108195 T - 176030 [...]
-
To display result with some infos such as execution duration, script's name, shell type, current script path and script's user, type:
./langstat.sh dico.txt --infos
Output:
278814 - E 229938 - A 219131 - I 210391 - R 207889 - S 179165 - N 176030 - T 158282 - O [...] Script executed during 7 seconds Script's name : ./langstat.sh Shell type : /bin/bash Current Script path : /vagrant User : vagrant