?

Log in

No account? Create an account

Previous Entry | Next Entry

Report Generation using AWK



"workingdet" is the file which contains the number of hours each employee has worked.

The fields are:
Emloyee Month Designation HoursWorked

$ cat workingdet
A Jan clerk (02:45)
B Jan Salesman (02:12)
C Jan Accountant (03:12)
A Feb clerk (01:10)
B Feb Salesman (11:10)
B March Salesman (3:10)
C Feb Accountant (3:34)

Here is something with AWK to calculate the total hours each Employee worked.

$ cat workingdet | awk '{print $0 ":" $4}' | sed 's/(//g'| sed 's/)//g' | awk -F ":" '{x=$3*60 + $4 ;print $0 " " x}' | awk '{emp[$1]+=$NF} END{for(i in emp){print i,"Total hours",emp[i],"mins";}}'
A Total hours 235 mins
B Total hours 992 mins
C Total hours 406 mins

$ cat workingdet | awk '{print $0 ":" $4}' | sed 's/(//g'| sed 's/)//g' | awk -F ":" '{x=$3*60 + $4 ;print $0 " " x}' | awk '{emp[$1]+=$NF} END{for(i in emp){printf "%c Total Hours %d:%d",i,emp[i]/60,emp[i]%60;printf "\n"}}'
A Total Hours 3:55
B Total Hours 16:32
C Total Hours 6:46

Profile

jaduks
Jadu Kumar Saikia

Latest Month

January 2008
S M T W T F S
  12345
6789101112
13141516171819
20212223242526
2728293031  
Powered by LiveJournal.com
Designed by chasethestars