Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
-
The problem statement, all variables and given/known data:
Write an awk script(company.awk) for the workers file to find the number of workers of each departman, total salary that is the sum of the salaries of each departmant workers, total salary of all departments and total salary average.(Total average should be calculated by dividing total salary to the total number of workers) -
Relevant commands, code, scripts, algorithms:
Workers file;
Alisan Baltaci, 23, Engineer, CUS, 1, 1800
Kadir Yenigun, 25, Technician, CIS, 2, 1000
Hande Gunay, 21, Secretary, 1, 850
Baran Tiryaki, 29, Engineer, SRT, 4, 2500
Bahar Topak, 26, Engineer, CIS, 3, 2000
Cihan Kurt, 28, Technician, SRT, 5, 1250
Sezen Agaoglu, 25, Engineer, CUS, 3, 2000
Kaan Yuksel, 21, Technician, CUS, 2, 1000
Irem Sozeri, 23, Engineer, CUS, 1, 1800
Dilan Colpan, 24, Secretary, CIS, 4, 1000
Output should be like this;
DEPARTMENTS & SALARIES
Department Workers TotalSalary Average
--------------------------------------------------------------
CUS 4 6600 1650
CIS 3 4000 1333.3
SRT 3 4600 1533.3
--------------------------------------------------------------
GRAND TOTAL 10 15200 1520
Only it should be used awk commands & scripts.
- The attempts at a solution (include all code and scripts):
In awk scripts;
BEGIN{print"DEPARTMENTS & SALARIES"
print"Department Workers TotalSalary Average"
print"---------------------------------------------------------"}
{FS=","
GFS="\t"}
{if(/CUS/)
{cus_no++;
cus_tot+=$6;}
else if(/CIS/)
{cis_no++;
cis_tot+=$6;}
else if(/SRT/)
{srt_no++;
srt_tot+=$6;}
}
END{tot_workers=cus_no+cis_tot+srt_no;
tot_salary=cus_tot+cis_tot+srt_tot;
print"CUS",cus_no,cus_tot,cus_tot/cus_no
print"CIS",cis_no,cis_tot,cis_tot/cis_no
print"SRT",srt_no,srt_tot,srt_tot/srt_no
print"------------------------------------------------"
print"GRAND TOTAL",tot_workers,tot_salary,tot_salary/tot_workers}
When apply this script, the codes do not count first latter and output seems 1801 in first calculation. However, when I type a blank for firs line and I start to type workers file in second line, there is no problem.
The question is why. Why does script count first line when it is typed to first line in workers file?
- Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Bilkent University, Ankara(�ankaya), Turkey, Engin Zafer Kra�bedel, and CTE 218 (cte.bilkent.edu.tr/en/curriculum)
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).