A script can do this, but I do not see any advantage to you that would be accomplished by the merge. You can sort to group the records with duplicate values and then use a pair of nested loops to loop through the group with a given duplicate value in order to merge as the inner loop and an outer loop that loops through the entire found set.
But it's far easier to keep the records separate and use a summary report with a sub summary part and summary fields to display the data as a "merged" row of data. By deleting the body layout part from such a layout, you get one row of data for each merged group.
I forgot to mention that the data was displayed using a portal in another layout. Each entry has a fk_timesheet_id used to display the info on a Timesheet layout. Would it be possible to achieve the same results wihout a summary report? Or would it be possible to format a summary report to display the data from both layouts? I have never used a summary report before.