Question: Can someone help me with my code? It has to work in Linux using this bash command awk - f employee.awk awkinput Below is the

Can someone help me with my code?
It has to work in Linux using this bash command
awk -f employee.awk awkinput
Below is the code I have:
BEGIN {
FS =":"
OFS =""
totalSalary =0
employeeCount =0
projectCount =0
}
$1=="E"{
empid = $2
empname[empid]= $3
emptitle[empid]= $4
empsalary[empid]= $5
totalSalary += $5
employeeCount++
}
$1=="P"{
projid = $2
projname[projid]= $3
projmanager[projid]= $4
projectCount++
}
$1=="W"{
workid = $2
empid = $3
projid = $4
workingOn[projid][empid]=1
projEmployeeCount[projid]++
}
/^#/|| NF ==0{
next
}
END {
for (projid in projname){
print "|=" projname[projid]"============|======================|============|"
print "| Name | Title | Salary |"
print "|======================|=====================|============|"
salaryIndex =0
for (empid in workingOn[projid]){
empList[salaryIndex++]= empsalary[empid]":" empid
}
n = asort(empList, sortedEmpList, "@val_num_desc")
projSalaryTotal =0
for (i =1; i <= n; i++){
split(sortedEmpList[i], empInfo, ":")
empid = empInfo[2]
salary = empInfo[1]
if (empid == projmanager[projid]){
printf "|*%-19s |%-20s |%-10d |
", empname[empid], emptitle[empid], salary
} else {
printf "|%-20s |%-20s |%-10d |
", empname[empid], emptitle[empid], salary
}
projSalaryTotal += salary
}
projEmployeeCount[projid]=(projEmployeeCount[projid]==0)?1 : projEmployeeCount[projid]
projAvgSalary = projSalaryTotal / projEmployeeCount[projid]
printf "|======================|=====================|============|
"
print "employed on project: " projEmployeeCount[projid]" average salary: " projAvgSalary "
"
}
employeeAvgSalary = totalSalary / employeeCount
print "Employees:", employeeCount, "Projects:", projectCount
print "Total Salary:", totalSalary
printf "Employee Average Salary: %.2f
", employeeAvgSalary
}
Below is the output for the code above, I can't get it exactly how it is and I can't upload it as a photo because chegg won't take it.
|= Spice Mining =============|======================|============|
| Name| Title| Salary |
|============================|======================|============|
| Paul Atreides| Kwisatz Haderach|20000000|
| Leto Atreides| Duke|1500333|
| Shaddam Corrino IV| Padishah Emperor|1000000|
|*Vladimir Harkonnen| Baron|990000|
|============================|======================|============|
employed on project: 4 average salary: 5872583.25
|= Bene Gesserit Schemes ====|======================|============|
| Name| Title| Salary |
|============================|======================|============|
| Irulan Corrino| Princess|980000|
|*Lady Jessica| Reverend Mother|500000|
|============================|======================|============|
employed on project: 2 average salary: 740000.00
|= Muad'Dib's Jihad =========|======================|============|
| Name

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!