Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In the data file employees.dat we have employee records with the following field

ID: 3707430 • Letter: I

Question

In the data file employees.dat we have employee records with the following fields of information (ID, FN, LN, D, #) where ID: Employee identification number FN: Employee first name LN: Employee last name D: Department #1 Office number Write a shell script for processing employees.dat in such a way that we get the list of records (ID, FN, LN) and the total number of employees in the standard output as well as the file employees_by_office.dat that contains employee records with the following fields of information (#, ID, FN, LN, D). Records in the file employees_by_office.dat must be sorted by the key #, and fields are separated by the symbol":";

Explanation / Answer

awk '{print $1, $2, $3}' employees.dat
head -n 1 employees.dat | awk '{print $5 ":" $1 ":" $2 ":" $3 ":" $4}' > employees_by_office.dat
tail -n +2 employees.dat | sort -k 5 -n | awk '{print $5 ":" $1 ":" $2 ":" $3 ":" $4}' >> employees_by_office.dat

I will explain it line by line.

first line will print ID,FN,LN in dat file

second line will add header ie (#:ID:FN:SN:D)

third line will sort data in input file based on column # and print it as (#:ID:FN:SN:D)