Question 1
Based on HW 6, Part II Problem 2, (or the script file “sub” on the last page of Lab6 Handout), please modify your bash/sed script “mysedprog” so that it will
remove the blank line(s),
delete the record for Nancy, and
substitute Jerry’s record with Anna’s record (Anna 95 97 98).
Please test it using “sed –f mysedprog mysedfile” and make sure the output is correct, and then provide your “mysedprog” below along with the output of the execution of the script:
Question 2
By using “last” command without an option, the login time period is displayed as follow:
$ last
cfs264su pts/0 35.139.208.173 Mon Jun 17 22:33 – 22:42 (00:08)cfs264su pts/20 152.117.114.217 Mon Jun 17 21:07 – 21:08 (00:00)
| grep “Jun 17” | head -2cfs264su pts/0 35.139.208.173 Mon Jun 17 22:33:20 2024 – Mon Jun 17 22:42:06 2024 (00:08)cfs264su pts/20 152.117.114.217 Mon Jun 17 21:07:17 2024 – Mon Jun 17 21:08:09 2024 (00:00)
Question 3:
Based on HW 7, Part II Problem 1, please create a file called “myloginfile” as shown below and then write an awk scriptto determine how many logins in file “myloginfile” spent less than an hour on the system.
$ last | grep “Jun 17” > myloginfile$ cat myloginfilecfs264su pts/0 35.139.208.173 Mon Jun 17 22:33 – 22:42 (00:08)cfs264su pts/20 152.117.114.217 Mon Jun 17 21:07 – 21:08 (00:00)cfs264su pts/17 68.46.76.194 Mon Jun 17 20:55 – 21:31 (00:35)cfs264su pts/6 76.156.71.67 Mon Jun 17 20:54 – 21:42 (00:48)cfs264su pts/22 73.62.176.252 Mon Jun 17 20:43 – 21:23 (00:40)cfs264su pts/21 63.231.165.128 Mon Jun 17 20:42 – 21:38 (00:55)cfs264su pts/20 152.117.114.217 Mon Jun 17 20:40 – 20:49 (00:08)… … …$
Please provide your awk script below along with the output of the execution of the script:
Question 4:
Based on HW 5, Part II Problem 2, please write a shell script with a for-loop, which displays all the readablebut NOTexecutable files under /etc directory. Your script should NOTdisplay any directories. Please test your script on our server and provide your script below along with the output of the execution of your script.
Question 5:
Please use the solution of HW7, Part II Problem 2, (or the script file “awkc8” in Lab7 Handout) as a template to write a shell/awk script, myaverage4, that reads in 4 numbers and then uses a self-defined function to compute the average. The average should be displayed in the main program, not inside the function. Please use the following testing cases to test your script:
$ ./myaverage4 2 7 4 3The average is 4$ ./myaverage4 -2 -1 -4 -5The average is -3