I hate to ask the group this but... 
Author Message
 I hate to ask the group this but...

Quote:

>I'm trying to format data that has fields I want to
>combine into single lines by date.  

>   "20-1-13:CVP,1591,PRTL,NEND,,1-DAY,8-3,0-0"
>   "20-1-13:ESP,7,PRTL,NEND,,1-DAY,8-3,0-0"
>   "20-1-13:SESP,7,PRTL,NEND,,1-DAY,8-3,0-0"
>   "20-1-13:OOFS,7,PRTL,NEND,,1-DAY,8-3,0-0"
>   "20-1-13:UAS,480,PRTL,NEND,,1-DAY,8-3,0-0"
>   "20-1-13:CVP,8471,PRTL,NEND,,1-DAY,8-2,0-0"
>   "20-1-13:ESP,58,PRTL,NEND,,1-DAY,8-2,0-0"
>   "20-1-13:SESP,58,PRTL,NEND,,1-DAY,8-2,0-0"
>   "20-1-13:OOFS,58,PRTL,NEND,,1-DAY,8-2,0-0"
>   "20-1-13:UAS,1626,PRTL,NEND,,1-DAY,8-2,0-0"
>   "20-1-13:CVP,20616,PRTL,NEND,,1-DAY,8-1,0-0"
>   "20-1-13:ESP,245,PRTL,NEND,,1-DAY,8-1,0-0"
>   "20-1-13:BESP,29,PRTL,NEND,,1-DAY,8-1,0-0"
>   "20-1-13:SESP,198,PRTL,NEND,,1-DAY,8-1,0-0"
>   "20-1-13:OOFS,196,PRTL,NEND,,1-DAY,8-1,0-0"
>   "20-1-13:UAS,7028,PRTL,NEND,,1-DAY,8-1,0-0"
>   "20-1-13:CVP,37620,PRTL,NEND,,1-DAY,7-31,0-0"
>   "20-1-13:ESP,513,PRTL,NEND,,1-DAY,7-31,0-0"
>   "20-1-13:BESP,41,PRTL,NEND,,1-DAY,7-31,0-0"
>   "20-1-13:SESP,466,PRTL,NEND,,1-DAY,7-31,0-0"
>   "20-1-13:OOFS,466,PRTL,NEND,,1-DAY,7-31,0-0"
>   "20-1-13:UAS,6973,PRTL,NEND,,1-DAY,7-31,0-0"
>   "20-1-13:CVP,72,COMPL,NEND,,1-DAY,7-30,0-0"
>   "20-1-13:ESP,2,COMPL,NEND,,1-DAY,7-30,0-0"

>I want it to look like this:

>08-03::CVP,1591,ESP,7,SESP,7,OOFS,7,UAS,480
>08-02::CVP,8471,ESP,58,SESP,58,OOFS,58,UAS,1626
>08-01::CVP,20616,ESP,245,BESP,29,SESP,198,OOFS,196,UAS,7028
>07-31::CVP,37620,ESP,513,BESP,41,SESP,466,OOFS,466,UAS,6973
>07-30::CVP,72,ESP,2

BEGIN {
   FS = ","

Quote:
}

{  # get rid of the beginning, before ":"
   colon_pos = index($0, ":")
   $0 = substr($0, colon_pos + 1)

   # format the date string
   split($7, date_arr, "-")
   month = sprintf("%02d", date_arr[1])
   day   = sprintf("%02d", date_arr[2])
   date_form = month "-" day

   # build up result string
   if (result[date_form] == "") {
      result[date_form] = date_form "::" $1 "," $2
   }
   else {
      result[date_form] = result[date_form] "," $1 "," $2
   }

Quote:
}

END {
   for (ind in result) {
      print result[ind]
   }

Quote:
}

The resulst must still be processed with "sort".

Learn about the "associative arrays" in awk (here respresented
by "result[date_form]". This feature of awk's will make your
life look easier again and again.

--
hans juergen



Tue, 03 Feb 2004 14:48:28 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. I hate to ask the group this but...

2. Does this news group HATE forth

3. Does this news group HATE forth

4. Group type descriptor - asking again for information

5. Rexx/PalmOS group on Yahoo (http://groups.yahoo.com/group/r-e-x-x_palmos/)

6. click the link for the best google group http://groups-beta.google.com/group/boysworld

7. Art and all that Jazz: they are hating before lazy, without sad, alongside wet balls

8. Why do people hate VSAM?

9. Why do people hate VSAM?

10. Why do you hate C++ ?

11. why (non-smalltalk) programmers hate smalltalk

12. I hate reports<g>

 

 
Powered by phpBB® Forum Software