Question: write a script named word_counts.sh that prints out how many words are on each line of standard input, as well as the total number of
write a script named word_counts.sh that prints out how many words are on each line of standard input, as well as the total number of words at the end. The script should take no arguments. Instead, the script must work by reading every line of standard input (using a while loop) and counting the number of words on each line separately. The script is intended to work with standard input coming from a pipe, which will most often come from a cat command to print a file. Here is an example, showing the contents of a file then using the word_counts.sh script:
------------------------------------------------------------------------------------------------------------
[user@localhost ~]$ cat jedi_code
Jedi code:
There is no emotion, there is peace.
There is no ignorance, there is knowledge.
There is no passion, there is serenity.
There is no chaos, there is harmony.
There is no death, there is the Force.
------------------------------------------------------------------------------------------------------------------------------------
[user@localhost ~]$ cat jedi_code | word_counts.sh
Line 1: 2
Line 2: 7
Line 3: 7
Line 4: 7
Line 5: 7
Line 6: 8
Total: 38
[user@localhost ~]$
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
