I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want.
The vendor wants me to submit three fields to them. Field 1 is the studentid field, field 2 is to be the building number and field 3 is a comma (and space char) delimited field holding periods.
This is what I have out of our records system now. Basically studentid, the periods, then the building number last. Each student is only listed once, so field 1 is unique in the input file 'absentees'.
250,1,2,3,45
255,2,4,6,8,10,45
1005,1,50
2099,1,2,51
I'd like to move the last field to the second position. Then enclose the remaining fields into one field with double quotes. Only if more than one period though (see third record for example of a record with only 1 period). So basically I need to get it looking like this (header row just fyi):
sid,bldg,periods
250,45,"1, 2, 3"
255,45,"2, 4, 6, 8, 10"
1005,50,1
2099,51,"1, 2"
I've used sed and cut to rearrange the order of fields when the number of fields are fixed. Not sure how to do it with a random number of fields though. Really not sure how to get the double quotes in there with comma and a space char.
I'm on hp-ux, so just awk is avail to me. (no gawk or nawk)
thanks in advance for any suggestions