I have a CSV file who has row by row data. The scenerio is that 2 of my columns have same values all the time.
Suppose, if in the row 1, column 0 and column 1 have the same value it simple store it in array first with its other values whom I want to loop.
On the next iteration, it checks if column 0 and column 1 values already exists in previous array, so loop 1st column and that column data to new array till from the preceding rows column 0 and column 1 have different values.
Here is the CSV file data:
PickTicketNumber OrderNumber LineItemUpc LineItemUnitPrice LineItemQuantity
218837 204127 LR8025BLKMD 58 4
218837 204127 LR8025BLKLG 58 3
218837 204127 LR8475HEASM 54 1
218837 204127 LR8770ROYLG 53 1
218838 204128 LR8475HEAXS 54 1
218838 204128 LR8475HEASM 54 2
218838 204128 LR8475HEAMD 54 2
218838 204128 LR8475HEALG 54 1
218838 204128 LR8917BLKXS 58 1
218838 204128 LR8917BLKSM 58 1
218838 204128 LR8917BLKMD 58 1
218838 204128 LR8917BLKLG 58 1
218838 204128 LR6382BLKXS 48 1
218838 204128 LR6382BLKSM 48 2
218838 204128 LR6382BLKMD 48 2
218838 204128 LR6382BLKLG 48 1
218838 204128 LR8475BLKSM 54 2
218838 204128 LR8475BLKMD 54 2
218838 204128 LR8475BLKLG 54 1
218839 204130 LR8878HEAXL 63 1
As its clear here, 218837 204127 exists 4 times so i simply want it one time and loop its LineItemUpc LineItemUnitPrice LineItemQuantity.
In the final result I would like to see the result this way:
218837 204127
one time only and if again it exists in next row so loop its LineItemUpc LineItemUnitPrice LineItemQuantity again. Means in the loop I want :
LR8025BLKMD 58 4
LR8025BLKLG 58 3
LR8475HEASM 54 1
LR8770ROYLG 53 1
Same for rest of the elements as well.
Means one PickTicketNumber OrderNumber and loop all their values in the upcoming rows having same PickTicketNumber OrderNumber until and unless new PickTicketNumber OrderNumber comes up with new PickTicketNumber OrderNumber.
In the end my final result would be:
<reference>218837 / 204127</reference>
<line>LR8025BLKMD</line>
<price>58<price>
<qty>3<qty>
<line>LR8025BLKLG</line>
<price>58<price>
<qty>1<qty>
<line>LR8475HEASM</line>
<price>54<price>
<qty>1<qty>
<line>LR8770ROYLG</line>
<price>53<price>
<qty>1<qty>