Question
1a. Write a script which receives a list of strings as parameters. Input an index string. Iterate through the list of strings and apply the
1a. Write a script which receives a list of strings as parameters. Input an index string. Iterate through the list of strings and apply the `expr index ` operation on each string using the index string as the index (see chapter 7 for more information about how expr index works). Output the string and the result of the index operation. When done, run it passing the string
abacab foxtrot duke trespass
and input the index string of abcd. Your output should be abacab 1, duke 1, foxtrot 0, trespass 6.
1b.
Write a script to compute payroll information for the people in the employees.txt file that you downloaded. Each row of this file consists of a persons last name, hours and wages. To compute pay, use an if-then-else statement using this formula:
Hours <= 40 pay = hours * wages
Hours > 40 pay = 40 * wages + 2 * (hours 40) * wages
We cant use time and a half (1.5) for overtime, so we use 2. Output for each employee their pay and also output the total number of employees processed and the average pay computed.
1c. Examine the file students.txt that you downloaded at the start of the lab. Each row of this file contains a students first name, last name, major, and 5 test scores. Write a script that uses a while read statement to input all of the data, line by line, compute the average test score and then assign a letter grade (see the logic on page 15 of the text). The 5th test is worth double (you should divide by 6 instead of 5 since test 5 is worth twice as much). Output for each student, the students last name, major and letter grade. Additionally, sum up the number of students who passed (got at least a D or higher) and the number of students who failed. When you run your script, remember to redirect input from students.txt.
1d.
Write a script which is passed a list of items (files, directories, links, etc) in the current directory as parameters. The script will iterate through this list, obtaining the long listing for each item and convert the permissions of the item into the 3-digit numeric equivalent. To accomplish this, you will have to store the permission portion in a variable. Assume the current filename is stored in the variable FILE. You can obtain the permissions using the following instruction:
permissions=`ls l $FILE | awk {print $1}`
The variable permissions will store the 11 characters in the permissions (the type of object, - for file, the 9 characters that make up the permissions, and a period that ends this sequence). You want to access characters 2-10. To access a single character, you can use notation like this ${permissions:INDEX:1} where INDEX is a number between 1 and 9 (recall that for this notation, the first character is at index 0). Now you want to look at the 3 sets of characters (1-3, 4-6, 7-9) and convert the r, w, and x into a value. You will need three separate sums, we can for instance call them first, second and third. If the character at index 1 is r, then add 4 to first, otherwise do nothing. If the character at index 2 is w, then add 2 to first, otherwise do nothing. And so forth. You might have if-then instructions that look like this:
if [ ${permissions:1:1} == r ]; then first=$((first=first+4)); fi
Once done, output the name of the file and the values of first, second and third. For instance: addresses.txt 744.
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