Question
You must create a script in Linux Bash. the script is sentences.sh, and uses a list of words given to the script to generate a
You must create a script in Linux Bash. the script is sentences.sh, and uses a list of words given to the script to generate a word chain, or a Markov Chain. The script accepts the text file name, as well as the length of the output list. It should accept these as a command line argument and write it's output to the terminal.
For example, given a file input.txt , where input.txt contains :
" Michael lost his own today, I am not sure if he will ever be the same. After the colander spilled I could not bring myself to face him. His eyes radiated transparently, filled with bloodlust. I wasn't sure what I could do or if anything could possibly even be done. It was suspected he had an unusual affinity for gravy and meat sauce, but the degree to which this has elevated has propelled us into a state of emergency. That is the purpose for our gathering here, our apparent fixation on Michael which I am sure once you witness in greater substance, you find as abominable as we do. We must take action."
we run the script:
$ ./sentences.sh input.txt 15
and we get output such as:
After the colander spilled I am sure once you find as abominable as we must.
Rules: -Script must verify argument before running such as:
-If the file exists
-the file can be read
-the number specified in the script must be larger than 0
Algorithm:
-Use three words to start
-Find fragments within input.txt to which begin with those words
-randomly select one of the fourth words
-repeat the process using the second and third starting word.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started