plz hlp me to get o/p in korn shell scripting

September 30, 2011 at 02:03:22
Specs: Windows XP
Input :
Date Time|Department|Hits
07/02/2011 08:08|abc|2
10/02/2011 11:33|bdf|1
11/04/2011 11:56|abc|5
12/05/2011 08:33|bdf|7

Output:
I would like to have the output as count of hits as per hrs(08,11) and department (abc, bdf)

08 - 9
11 - 6
abc - 7
bdf - 8


See More: plz hlp me to get o/p in korn shell scripting

Report •

#1
September 30, 2011 at 09:17:12
This works if the colon only exists in the time string:

awk ' BEGIN { FS="|" }
{

    retval=index($1, ":")
    # process the line if colon exists in field 1
    if(retval > 0)
       {
       # process the hours
       num=substr($1,(retval-2), 2)
       hrs[num] += $3

       # process the department
       dept[$2] += $3
       }

}
# print out the two arrays
END {
   for(i in hrs )
      printf("%s - %s\n", i, hrs[i])

   for(i in dept )
      printf("%s - %s\n", i, dept[i])
}

' datafile.txt


Report •
Related Solutions


Ask Question