Question: THIS IS A LINUX SHELL SCRIPTING QUESTION. I HAVE TWO WEDDINDS TO ATTEND THIS WEEKEND AND NEED SOME HELP. ALL I NEED IS SCREEN SHOTS
THIS IS A LINUX SHELL SCRIPTING QUESTION. I HAVE TWO WEDDINDS TO ATTEND THIS WEEKEND AND NEED SOME HELP. ALL I NEED IS SCREEN SHOTS OF .SH CODES SO THAT I CAN DO IT TOMORROW NIGHT ON MY END, THANK YOU.
write a script named print_lines.sh that uses head and tail together to print out a specific set of lines from a file. The script should take three arguments: the line number to start at, the line number to stop at, and the file to use. Here's an example run:
[user@localhost ~]$ print_lines.sh 7 10 /etc/passwd
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
[user@localhost ~]$
In this example, the script prints line 7 through 10 (inclusive) of the /etc/passwd file. Your script must do error checking. Specifically, you need to check all the following things:
1. You get the right number of arguments (3).
2. The file specified exists and is a normal file.
3. The first line number specified is less than or equal to the last line number specified.
4. The actual number of lines in the file is greater than the last line to be printed.
If any of those conditions are not true, you should print an appropriate error message to the user and stop. If they are all met, then you'll need to do a bit of arithmetic and use head and tail together to print out only the lines requested.
Once you've got it tested and working, TAKE A SCREENSHOT (3) of the output of the script using some example arguments.
TAKE A SCREENSHOT (4 print_lines.sh) your script.
Finally, 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 ~]$
Be sure to test your script thoroughly. When you're done, TAKE A SCREENSHOT (7) of the output of the script using some example inputs. TAKE A SCREENSHOT (8 word_counts.sh) your script.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
